예제 #1
0
 /**
  * Render/save the Custom Lead Routing Rules
  *
  * This method renders a grid of Custom Round Robin Rules and allows for new
  * rules to be created and saved. These rules are used in conjunction with
  * {@link AdminController::actionGetRoutingType} when the "Custom Round Robin"
  * lead distribution method is chosen.
  */
 public function actionRoundRobinRules()
 {
     $model = new LeadRouting();
     $users = User::getNames();
     unset($users['Anyone']);
     unset($users['admin']);
     $priorityArray = array();
     for ($i = 1; $i <= LeadRouting::model()->count() + 1; $i++) {
         $priorityArray[$i] = $i;
     }
     $dataProvider = new CActiveDataProvider('LeadRouting', array('criteria' => array('order' => 'priority ASC')));
     if (isset($_POST['LeadRouting'])) {
         $values = $_POST['Values'];
         $criteria = array();
         for ($i = 0; $i < count($values['field']); $i++) {
             $tempArr = array($values['field'][$i], $values['comparison'][$i], $values['value'][$i]);
             $criteria[] = implode(',', $tempArr);
         }
         $model->criteria = json_encode($criteria);
         $model->attributes = $_POST['LeadRouting'];
         $model->priority = $_POST['LeadRouting']['priority'];
         if (isset($_POST['group'])) {
             $group = true;
             $model->groupType = $_POST['groupType'];
         } else {
             $model->groupType = null;
         }
         $model->users = Fields::parseUsers($model->users);
         $check = LeadRouting::model()->findByAttributes(array('priority' => $model->priority));
         if (isset($check)) {
             $query = "UPDATE x2_lead_routing " . "SET priority=priority+1 " . "WHERE priority>='{$model->priority}'";
             $command = Yii::app()->db->createCommand($query);
             $command->execute();
         }
         if ($model->save()) {
             $this->redirect('roundRobinRules');
         }
     }
     $this->render('customRules', array('model' => $model, 'users' => $users, 'dataProvider' => $dataProvider, 'priorityArray' => $priorityArray));
 }
예제 #2
0
 /**
  * update calendar with id $id
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if (isset($_POST['X2Calendar'])) {
         // check for empty permissions
         if (!isset($_POST['X2Calendar']['viewPermission'])) {
             $model->viewPermission = '';
         }
         if (!isset($_POST['X2Calendar']['editPermission'])) {
             $model->editPermission = '';
         }
         // copy $_POST data into Calendar model
         foreach (array_keys($model->attributes) as $field) {
             if (isset($_POST['X2Calendar'][$field])) {
                 $model->{$field} = $_POST['X2Calendar'][$field];
                 $fieldData = Fields::model()->findByAttributes(array('modelName' => 'Calendar', 'fieldName' => $field));
                 if ($fieldData->type == 'assignment' && $fieldData->linkType == 'multiple') {
                     $model->{$field} = Fields::parseUsers($model->{$field});
                 } elseif ($fieldData->type == 'date') {
                     $model->{$field} = strtotime($model->{$field});
                 }
             }
         }
         $model->updatedBy = Yii::app()->user->name;
         $model->lastUpdated = time();
         $model->save();
         $this->redirect(array('view', 'id' => $model->id));
     }
     $admin = Yii::app()->settings;
     $googleIntegration = $admin->googleIntegration;
     $this->render('update', array('model' => $model, 'googleIntegration' => $googleIntegration));
 }
예제 #3
0
 public function actionChangePermissions($id)
 {
     $model = $this->loadModel($id);
     if (Yii::app()->params->isAdmin || Yii::app()->user->getName() == $model->createdBy) {
         $users = User::getNames();
         unset($users['admin']);
         unset($users['Anyone']);
         $str = $model->editPermissions;
         $pieces = explode(", ", $str);
         $model->editPermissions = $pieces;
         if (isset($_POST['Docs'])) {
             $model->attributes = $_POST['Docs'];
             $arr = $model->editPermissions;
             $model->editPermissions = Fields::parseUsers($arr);
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $id));
             }
         }
         $this->render('editPermissions', array('model' => $model, 'users' => $users));
     } else {
         $this->redirect(array('view', 'id' => $id));
     }
 }
예제 #4
0
 public function actionAddUser($id)
 {
     $users = User::getNames();
     unset($users['admin']);
     unset($users['']);
     foreach (Groups::model()->findAll() as $group) {
         $users[$group->id] = $group->name;
     }
     //$contacts = Contacts::getAllNames(); // very inefficient with large table
     $model = $this->loadModel($id);
     $users = Accounts::editUserArray($users, $model);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Accounts'])) {
         $temp = $model->assignedTo;
         $tempArr = $model->attributes;
         $model->attributes = $_POST['Accounts'];
         $arr = $_POST['Accounts']['assignedTo'];
         $model->assignedTo = Fields::parseUsers($arr);
         if ($temp != "") {
             $temp .= ", " . $model->assignedTo;
         } else {
             $temp = $model->assignedTo;
         }
         $model->assignedTo = $temp;
         // $changes=$this->calculateChanges($tempArr,$model->attributes);
         // $model=$this->updateChangelog($model,$changes);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('addUser', array('model' => $model, 'users' => $users, 'action' => 'Add'));
 }
예제 #5
0
 /**
  * Create a static page.
  *
  * This method allows the admin to create a static page to go on the top bar
  * menu.  The page is a basic doc editor which is then saved as a Module record
  * of type "Document."
  */
 public function actionCreatePage()
 {
     $existingDocs = X2Model::model('Docs')->findAll();
     $existingDocs = CHtml::listData($existingDocs, 'id', 'name');
     $model = new Docs();
     $users = User::getNames();
     if (isset($_POST['Docs'])) {
         $model->attributes = $_POST['Docs'];
         $arr = $model->editPermissions;
         if (isset($arr)) {
             $model->editPermissions = Fields::parseUsers($arr);
         }
         $model->createdBy = 'admin';
         $model->createDate = time();
         $model->lastUpdated = time();
         $model->updatedBy = 'admin';
         $module = new Modules();
         $module->adminOnly = 0;
         $module->toggleable = 1;
         $module->custom = 1;
         $module->visible = 1;
         $module->editable = 0;
         $module->searchable = 0;
         $module->menuPosition = Modules::model()->count();
         $module->name = 'document';
         $module->title = $model->name;
         if ($module->save()) {
             if ($model->save()) {
                 $this->redirect(array('/docs/docs/view', 'id' => $model->id, 'static' => 'true'));
             }
         }
     } else {
         if (isset($_POST['existingDoc'])) {
             $existingDoc = urldecode($_POST['existingDoc']);
             $docRecord = X2Model::model('Docs')->findByAttributes(array('name' => $existingDoc));
             if (!is_null($docRecord)) {
                 $module = new Modules();
                 $module->adminOnly = 0;
                 $module->toggleable = 1;
                 $module->custom = 1;
                 $module->visible = 1;
                 $module->editable = 0;
                 $module->searchable = 0;
                 $module->menuPosition = Modules::model()->count();
                 $module->name = 'document';
                 $module->title = $docRecord->name;
                 if ($module->save()) {
                     echo $docRecord->id;
                     Yii::app()->end();
                 } else {
                     $this->refresh();
                 }
             }
         }
     }
     $this->render('createPage', array('model' => $model, 'users' => $users, 'existingDocs' => $existingDocs));
 }