Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • AdminController
  • Api2Controller
  • ApiController
  • BugReportsController
  • CommonSiteControllerBehavior
  • ProfileController
  • RelationshipsController
  • SearchController
  • SiteController
  • StudioController
  • TemplatesController
  • TopicsController
  • x2base
  • X2Controller
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program is free software; you can redistribute it and/or modify it under
  7:  * the terms of the GNU Affero General Public License version 3 as published by the
  8:  * Free Software Foundation with the addition of the following permission added
  9:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 10:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program is distributed in the hope that it will be useful, but WITHOUT
 14:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 15:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 16:  * details.
 17:  * 
 18:  * You should have received a copy of the GNU Affero General Public License along with
 19:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 20:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21:  * 02110-1301 USA.
 22:  * 
 23:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code versions
 27:  * of this program must display Appropriate Legal Notices, as required under
 28:  * Section 5 of the GNU Affero General Public License version 3.
 29:  * 
 30:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 31:  * these Appropriate Legal Notices must retain the display of the "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37: class TemplatesController extends x2base {
 38: 
 39:     public $modelClass = 'Templates';
 40: 
 41:     public function behaviors(){
 42:         return array_merge(parent::behaviors(), array(
 43:             'X2MobileControllerBehavior' => array(
 44:                 'class' => 
 45:                     'application.modules.mobile.components.behaviors.X2MobileControllerBehavior'
 46:             ),
 47:             'QuickCreateRelationshipBehavior' => array(
 48:                 'class' => 'QuickCreateRelationshipBehavior',
 49:             ),
 50:         ));
 51:     }
 52: 
 53:     /**
 54:      * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
 55:      * using two-column layout. See 'protected/views/layouts/column2.php'.
 56:      */
 57:     public function actionGetItems($term){
 58:         X2LinkableBehavior::getItems ($term);
 59:     }
 60: 
 61:     /**
 62:      * Displays a particular model.
 63:      * @param integer $id the ID of the model to be displayed
 64:      */
 65:     public function actionView($id) {
 66:         $type='templates';
 67:         $model=$this->loadModel($id);
 68:         parent::view($model, $type);
 69:     }
 70: 
 71:     /**
 72:      * Creates a new model.
 73:      * If creation is successful, the browser will be redirected to the 'view' page.
 74:      */
 75:     public function actionCreate() {
 76:         $model=new Templates;
 77:         $users=User::getNames();
 78: 
 79:         if(isset($_POST['Templates'])) {
 80:             $temp = $model->attributes;
 81:             $model->setX2Fields($_POST['Templates']);
 82: 
 83:             if(isset($_POST['x2ajax'])){
 84:                 $ajaxErrors = $this->quickCreate ($model);
 85:             } else{
 86:                 if ($model->save ()) {
 87:                     $this->redirect(array('view', 'id' => $model->id));
 88:                 }
 89:             }
 90:         }
 91: 
 92: 
 93:         if(isset($_POST['x2ajax'])){
 94:             $this->renderInlineCreateForm ($model, isset ($ajaxErrors) ? $ajaxErrors : false);
 95:         } else {
 96:             $this->render('create',array(
 97:                 'model'=>$model,
 98:                 'users'=>$users,
 99:             ));
100:         }
101:     }
102: 
103:     /**
104:      * Updates a particular model.
105:      * If update is successful, the browser will be redirected to the 'view' page.
106:      * @param integer $id the ID of the model to be updated
107:      */
108:     public function actionUpdate($id) {
109:         $model = $this->loadModel($id);
110:         $users = User::getNames();
111: 
112:         if(isset($_POST['Templates'])) {
113:             $temp = $model->attributes;
114:             $model->setX2Fields($_POST['Templates']);
115:             parent::update($model,$temp,'0');
116:         }
117: 
118:         $this->render('update',array(
119:             'model'=>$model,
120:             'users'=>$users,
121:         ));
122:     }
123: 
124:     /**
125:      * Deletes a particular model.
126:      * If deletion is successful, the browser will be redirected to the 'admin' page.
127:      * @param integer $id the ID of the model to be deleted
128:      */
129:     public function actionDelete($id) {
130:         if(Yii::app()->request->isPostRequest) {
131:             // we only allow deletion via POST request
132:             $model=$this->loadModel($id);
133:             $this->cleanUpTags($model);
134:             $model->delete();
135: 
136:             /* if AJAX request (triggered by deletion via admin grid view), we should not redirect 
137:                the browser */
138:             if(!isset($_GET['ajax']))
139:                 $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
140:         } else {
141:             throw new CHttpException(
142:                 400,'Invalid request. Please do not repeat this request again.');
143:         }
144:     }
145: 
146:     /**
147:      * Lists all models.
148:      */
149:     public function actionIndex() {
150:         $model=new Templates('search');
151:         $this->render('index', array('model'=>$model));
152:     }
153: 
154:     /**
155:      * Manages all models.
156:      */
157:     public function actionAdmin() {
158:         $model=new Templates('search');
159:         $this->render('admin', array('model'=>$model));
160:     }
161: 
162:     /**
163:      * Performs the AJAX validation.
164:      * @param CModel the model to be validated
165:      */
166:     protected function performAjaxValidation($model) {
167:         if(isset($_POST['ajax']) && $_POST['ajax']==='templates-form') {
168:             echo CActiveForm::validate($model);
169:             Yii::app()->end();
170:         }
171:     }
172: }
173: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0