/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($model, $name) { $users=UserChild::getNames(); $accounts=AccountChild::getNames(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST[$name])) { $model->attributes=$_POST[$name]; $model=$this->updateChangelog($model); if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('update',array( 'model'=>$model, 'users'=>$users, 'accounts'=>$accounts, )); }
public function actionChangePermissions($id){ $model=$this->loadModel($id); if(Yii::app()->user->getName()=='admin' || Yii::app()->user->getName()==$model->createdBy){ $users=UserChild::getNames(); unset($users['admin']); unset($users['Anyone']); $str=$model->editPermissions; $pieces=explode(", ",$str); $model->editPermissions=$pieces; if(isset($_POST['DocChild'])){ $model->attributes=$_POST['DocChild']; $arr=$model->editPermissions; $model->editPermissions=AccountChild::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)); } }
public function actionCreatePage() { $model=new DocChild; $users=UserChild::getNames(); if(isset($_POST['DocChild'])) { $model->attributes=$_POST['DocChild']; $arr=$model->editPermissions; if(isset($arr)) $model->editPermissions=AccountChild::parseUsers($arr); $model->text=$_POST['msgpost']; $model->createdBy='admin'; $model->createDate=time(); $model->lastUpdated=time(); $model->updatedBy='admin'; $admin=Admin::model()->findByPk(1); if(isset($admin)) { if($admin->menuOrder!="") { $admin->menuOrder.=":".mb_ereg_replace(':',':',$model->title); $admin->menuVisibility.=":1"; $admin->menuNicknames.=":".mb_ereg_replace(':',':',$model->title); } else{ $admin->menuOrder=$model->title; $admin->menuVisibility.=":1"; $admin->menuNicknames=$model->title; } $admin->save(); } if($model->save()) { $this->redirect(array('viewPage','id'=>$model->id)); } } $this->render('createPage',array( 'model'=>$model, 'users'=>$users, )); }
public function actionLeadPerformance() { $dateRange = $this->getDateRange(); $model = new Contacts('search'); if (isset($_GET['Contacts'])) { $model->attributes = $_GET['Contacts']; } if (isset($_GET['Contacts']['company_id'], $_GET['Contacts']['company']) && !empty($_GET['Contacts']['company'])) { // check the ID, if provided $linkId = $_GET['Contacts']['company_id']; if (!empty($linkId) && CActiveRecord::model('Accounts')->countByAttributes(array('id' => $linkId))) { // if the link model actually exists, $model->company = $linkId; } // then use the ID as the field value } if (!empty($_GET['Contacts']['company']) && !ctype_digit($_GET['Contacts']['company'])) { // if the field is sitll text, try to find the ID based on the name $linkModel = CActiveRecord::model('Accounts')->findByAttributes(array('name' => $_GET['Contacts']['company'])); if (isset($linkModel)) { $model->company = $linkModel->id; } } $attributeConditions = ''; $attributeParams = array(); // $attributeConditions = array(); //$model->attributes foreach ($model->attributes as $key => $value) { if (!empty($value)) { $attributeConditions .= ' AND x2_contacts.' . $key . '=:' . $key; $attributeParams[':' . $key] = $value; } } $workflow = 1; if (isset($_GET['workflow'])) { if (ctype_digit($_GET['workflow'])) { $workflow = $_GET['workflow']; } if ($workflow != 1 && $workflow != 2) { // only these 2 workflows are allowed $workflow = 1; } $stageIds = array(1 => array('i' => 3, 'e' => 12, 's' => 16), 2 => array('i' => 3, 'e' => 7, 's' => 10)); // SELECT COUNT(`a`.*) as `count1`, COUNT(`b`.*) as `count2`, assignedTo, stageNumber FROM `x2_actions` `a`, `x2_actions` `b` WHERE a.type="workflow" AND b.type="workflow" AND a.workflowId=1 AND b.workflowId=1 AND `a`.stageNumber=1 AND `b`.stageNumber=2 GROUP BY a.assignedTo, a.stageNumber, b.stageNumber $users = UserChild::getNames(); // $groups = Groups::getNames(); // $assignedTo = array_keys($groups) + array_keys($users); $assignedTo = array_keys($users); $data = array(); $totals = array('id' => '', 'name' => Yii::t('dashboard', 'Total'), 'leads' => 0, 'interviewed' => 0, 'enrolled' => 0, 'started' => 0); for ($i = 0, $size = sizeof($assignedTo); $i < $size; $i++) { $data[$i]['id'] = $assignedTo[$i]; $data[$i]['name'] = $users[$assignedTo[$i]]; if ($data[$i]['id'] == 'Anyone') { $assignmentCheck = '(x2_contacts.assignedTo IS NULL OR x2_contacts.assignedTo="" OR x2_contacts.assignedTo="Anyone")'; $data[$i]['id'] = ''; } else { $assignmentCheck = 'x2_contacts.assignedTo="' . $data[$i]['id'] . '"'; } $data[$i]['leads'] = Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_contacts')->where('assignedTo="' . $assignedTo[$i] . '" AND createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end'] . $attributeConditions, $attributeParams)->queryScalar(); $totals['leads'] += $data[$i]['leads']; $row = Yii::app()->db->createCommand()->select('SUM(IF(x2_actions.stageNumber=' . $stageIds[$workflow]['i'] . ',1,0)) AS interviewed, SUM(IF(x2_actions.stageNumber=' . $stageIds[$workflow]['e'] . ',1,0)) AS enrolled, SUM(IF(x2_actions.stageNumber=' . $stageIds[$workflow]['s'] . ',1,0)) AS started, x2_contacts.assignedTo AS assignedTo')->from('x2_contacts')->join('x2_actions', 'x2_actions.associationId=x2_contacts.id AND x2_actions.associationType="contacts"')->where('x2_actions.type="workflow" AND x2_actions.workflowId=' . $workflow . ' AND x2_actions.completeDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end'] . ' AND ' . $assignmentCheck . ' AND (SELECT COUNT(*) FROM x2_contacts WHERE x2_contacts.id=x2_actions.associationId ' . $attributeConditions . ') > 0', $attributeParams)->queryRow(); $data[$i]['interviewed'] = isset($row['interviewed']) ? $row['interviewed'] : 0; $data[$i]['enrolled'] = isset($row['enrolled']) ? $row['enrolled'] : 0; $data[$i]['started'] = isset($row['started']) ? $row['started'] : 0; $totals['interviewed'] += $data[$i]['interviewed']; $totals['enrolled'] += $data[$i]['enrolled']; $totals['started'] += $data[$i]['started']; if (array_sum($data[$i]) == 0) { unset($data[$i]); } } $data[] = $totals; // die(var_dump($data)); // $sql = 'SELECT COUNT(*) as `count`,assignedTo, stageNumber FROM `x2_actions` WHERE type="workflow" AND workflowId=1 GROUP BY assignedTo, stageNumber'; $dataProvider = new CArrayDataProvider($data, array('sort' => array(), 'pagination' => array('pageSize' => Yii::app()->params->profile->resultsPerPage))); } else { $dataProvider = null; } $this->render('leadPerformance', array('model' => $model, 'workflow' => $workflow, 'dataProvider' => $dataProvider, 'dateRange' => $dateRange)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $name = 'Contacts'; $model = $this->loadModel($id); $users=UserChild::getNames(); $accounts=AccountChild::getNames(); if(isset($_POST[$name])) { $temp=$model->attributes; $model->attributes=$_POST[$name]; $attributeLabels = ContactChild::attributeLabels(); if($model->address == $attributeLabels['address']) $model->address = ''; if($model->city == $attributeLabels['city']) $model->city = ''; if($model->state == $attributeLabels['state']) $model->state = ''; if($model->zipcode == $attributeLabels['zipcode']) $model->zipcode = ''; if($model->country == $attributeLabels['country']) $model->country = ''; $changes=$this->calculateChanges($temp,$model->attributes); $model=$this->updateChangelog($model,$changes); if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('update',array( 'model'=>$model, 'users'=>$users, 'accounts'=>$accounts, )); }
public function actionAddUser($id) { $users=UserChild::getNames(); $contacts=ContactChild::getAllNames(); $model=$this->loadModel($id); $users=AccountChild::editUserArray($users, $model); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Projects'])) { $temp=$model->assignedTo; $model->attributes=$_POST['Projects']; $arr=$model->assignedTo; $this->updateChangelog($model); $model->assignedTo=ProjectChild::parseUsers($arr); $temp.=', '.$model->assignedTo; $model->assignedTo=$temp; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('addUser',array( 'model'=>$model, 'users'=>$users, 'contacts'=>$contacts )); }
return false; }); "); $cs=Yii::app()->getClientScript(); $cs->registerScriptFile(Yii::app()->request->baseUrl.'/assets/js/test.js'); ?> <h2><?php echo Yii::t('contacts','Manage Contacts'); ?></h2> <?php echo Yii::t('app','You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.'); ?> <br /> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search',array( 'model'=>$model, 'users'=>UserChild::getNames(), )); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'contacts-grid', 'baseScriptUrl'=>Yii::app()->request->baseUrl.'/themes/'.Yii::app()->theme->name.'/css/gridview', 'template'=> '<div class="title-bar">' .CHtml::link(Yii::t('app','Advanced Search'),'#',array('class'=>'search-button')) . ' | ' .CHtml::link(Yii::t('app','Clear Filters'),array('index','clearFilters'=>1)) .'{summary}</div>{items}{pager}', 'dataProvider'=>$model->searchAdmin(), 'filter'=>$model, 'columns'=>array( //'id', 'firstName',
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model=$this->loadModel($id); $names=$this->parseType($model->type); $users=UserChild::getNames(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['ActionChild'])) { $temp=$model->attributes; $model->attributes=$_POST['ActionChild']; $dueDate = strtotime($model->dueDate); $model->dueDate = ($dueDate===false)? '' : $dueDate; //date('Y-m-d',$dueDate).' 23:59:59'; // default to being due by 11:59 PM $association = $this->getAssociation($model->associationType,$model->associationId); if($association != null) { $model->associationName = $association->name; } else { $model->associationName = 'None'; $model->associationId = 0; } $changes=$this->calculateChanges($temp,$model->attributes); $model=$this->updateChangelog($model,$changes); if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('update',array( 'model'=>$model, 'names'=>$names, 'users'=>$users, )); }
public function actionAddContact($id) { $users=UserChild::getNames(); $contacts=ContactChild::getAllNames(); $model=$this->loadModel($id); $contacts=SaleChild::editContactArray($contacts, $model); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Sales'])) { $temp=$model->associatedContacts; $tempArr=$model->attributes; $model->attributes=$_POST['Sales']; $arr=$model->associatedContacts; $model->associatedContacts=SaleChild::parseContacts($arr); $temp.=" ".$model->associatedContacts; $model->associatedContacts=$temp; $changes=$this->calculateChanges($tempArr,$model->attributes); $model=$this->updateChangelog($model,$changes); if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('addContact',array( 'model'=>$model, 'users'=>$users, 'contacts'=>$contacts, 'action'=>'Add' )); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model=$this->loadModel($id); $users=UserChild::getNames(); $contacts=ContactChild::getAllNames(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Cases'])) { $model->attributes=$_POST['Cases']; $model=$this->updateChangelog($model); $arr=$model->associatedContacts; $str=''; foreach($arr as $contact) { $str.=' '.$contact; } $str=substr($str,1); $model->associatedContacts=$str; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('update',array( 'model'=>$model, 'users'=>$users, 'contacts'=>$contacts, )); }