public function testAfterDelete() { $user = User::model()->findByPk('2'); if (X2_TEST_DEBUG_LEVEL > 1) { /**/ print 'id of user to delete: '; /**/ print $user->id; } // test calendar permissions deletion $this->assertNotEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('user_id' => $user->id)))); $this->assertNotEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('other_user_id' => $user->id)))); // assert that group to user records exist for this user $this->assertTrue(sizeof(GroupToUser::model()->findAllByAttributes(array('userId' => $user->id))) > 0); $this->assertTrue($user->delete()); X2_TEST_DEBUG_LEVEL > 1 && (print 'looking for groupToUser records with userId = ' . $user->id); GroupToUser::model()->refresh(); // assert that group to user records were deleted $this->assertTrue(sizeof(GroupToUser::model()->findAllByAttributes(array('userId' => $user->id))) === 0); // test profile deletion $this->assertTrue(sizeof(Profile::model()->findAllByAttributes(array('username' => $user->username))) === 0); // test social deletion $this->assertTrue(sizeof(Social::model()->findAllByAttributes(array('user' => $user->username))) === 0); $this->assertTrue(sizeof(Social::model()->findAllByAttributes(array('associationId' => $user->id))) === 0); // test event deletion $this->assertTrue(sizeof(Events::model()->findAll("user=:username OR (type='feed' AND associationId=" . $user->id . ")", array(':username' => $user->username))) === 0); // test calendar permissions deletion $this->assertEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('user_id' => $user->id)))); $this->assertEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('other_user_id' => $user->id)))); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { // $this->layout = '//layouts/column3'; $contact = $this->loadModel($id); $viewPermissions = $contact->assignedTo == Yii::app()->user->getName() || $contact->visibility == 1 || Yii::app()->user->getName() == 'admin'; /* x2temp */ $groups = GroupToUser::model()->findAllByAttributes(array('userId' => Yii::app()->user->getId())); $temp = array(); foreach ($groups as $group) { $temp[] = $group->groupId; } if (array_search($contact->assignedTo, $temp) !== false) { $viewPermissions = true; } if ($contact->visibility == '2') { $user = User::model()->findByAttributes(array('username' => $contact->assignedTo)); $groups = GroupToUser::model()->findAllByAttributes(array('userId' => $user->id)); $tempOne = array(); foreach ($groups as $group) { $tempOne[] = $group->groupId; } $userGroups = GroupToUser::model()->findAllByAttributes(array('userId' => Yii::app()->user->getId())); $tempTwo = array(); foreach ($userGroups as $userGroup) { $tempTwo[] = $userGroup->groupId; } if (count(array_intersect($tempOne, $tempTwo)) > 0) { $viewPermissions = true; } } if (is_numeric($contact->assignedTo)) { $contact->assignedTo = Groups::model()->findByPk($contact->assignedTo)->name; } /* end x2temp */ if ($viewPermissions) { User::addRecentItem('c', $id, Yii::app()->user->getId()); ////add contact to user's recent item list parent::view($contact, 'contacts'); } else { $this->redirect('index'); } }
/** * Gets a list of names of all users having a group in common with a user. * * @param integer $userId User's ID * @param boolean $cache Whether to cache or not * @return array */ public static function getGroupmates($userId, $cache = true) { if ($cache === true && ($groupmates = Yii::app()->cache->get('user_groupmates')) !== false) { if (isset($groupmates[$userId])) { return $groupmates[$userId]; } } else { $groupmates = array(); } $userGroups = self::getUserGroups($userId, $cache); $groupmates[$userId] = array(); if (!empty($userGroups)) { $groupParam = AuxLib::bindArray($userGroups, 'gid_'); $inGroup = AuxLib::arrToStrList(array_keys($groupParam)); $groupmates[$userId] = Yii::app()->db->createCommand()->select('DISTINCT(gtu.username)')->from(GroupToUser::model()->tableName() . ' gtu')->join(User::model()->tableName() . ' u', 'gtu.userId=u.id AND gtu.groupId IN ' . $inGroup, $groupParam)->queryColumn(); } if ($cache === true) { Yii::app()->cache->set('user_groupmates', $groupmates, 259200); } return $groupmates[$userId]; }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $links = GroupToUser::model()->findAllByAttributes(array('groupId' => $id)); foreach ($links as $link) { $link->delete(); } $contacts = X2Model::model('Contacts')->findAllByAttributes(array('assignedTo' => $id)); foreach ($contacts as $contact) { $contact->assignedTo = 'Anyone'; $contact->save(); } $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
/** * Obtains lead routing rules. * @param type $data * @return type */ public function getRoutingRules($data) { $admin =& Yii::app()->settings; $online = $admin->onlineOnly; Session::cleanUpSessions(); $sessions = Session::getOnlineUsers(); $criteria = new CDbCriteria(); $criteria->order = "priority ASC"; $rules = X2Model::model('LeadRouting')->findAll($criteria); foreach ($rules as $rule) { $arr = LeadRouting::parseCriteria($rule->criteria); $flagArr = array(); foreach ($arr as $criteria) { if (isset($data[$criteria['field']])) { $val = $data[$criteria['field']]; $operator = $criteria['comparison']; $target = $criteria['value']; if ($operator != 'contains') { switch ($operator) { case '>': $flag = $val >= $target; break; case '<': $flag = $val <= $target; break; case '=': $flag = $val == $target; break; case '!=': $flag = $val != $target; break; default: $flag = false; } } else { $flag = preg_match("/{$target}/i", $val) != 0; } $flagArr[] = $flag; } } if (!in_array(false, $flagArr) && count($flagArr) > 0) { $users = $rule->users; $users = explode(", ", $users); if (is_null($rule->groupType)) { if ($online == 1) { $users = array_intersect($users, $sessions); } } else { $groups = $rule->users; $groups = explode(", ", $groups); $users = array(); foreach ($groups as $group) { if ($rule->groupType == self::WITHIN_GROUPS) { $links = GroupToUser::model()->findAllByAttributes(array('groupId' => $group)); foreach ($links as $link) { $usernames[] = User::model()->findByPk($link->userId)->username; } } else { // $rule->groupType == self::BETWEEN_GROUPS $users[] = $group; } } if ($online == 1 && $rule->groupType == self::WITHIN_GROUPS) { foreach ($usernames as $user) { if (in_array($user, $sessions)) { $users[] = $user; } } } elseif ($rule->groupType == self::WITHIN_GROUPS) { $users = $usernames; } } if ($rule->groupType == self::WITHIN_GROUPS) { $users = array_values(array_intersect(Profile::model()->getUsernamesOfAvailableUsers(), $users)); } $users[] = $rule->rrId; $rule->rrId++; $rule->save(); return $users; } } }
$nonCustom = array(); $custom = array(); foreach ($fields as $field) { if ($field->custom == 0) { $nonCustom[$field->fieldName] = $field; } else { $custom[$field->fieldName] = $field; } } $temp = RoleToUser::model()->findAllByAttributes(array('userId' => Yii::app()->user->getId())); $roles = array(); foreach ($temp as $link) { $roles[] = $link->roleId; } /* x2temp */ $groups = GroupToUser::model()->findAllByAttributes(array('userId' => Yii::app()->user->getId())); foreach ($groups as $link) { $tempRole = RoleToUser::model()->findByAttributes(array('userId' => $link->groupId, 'type' => 'group')); $roles[] = $tempRole->roleId; } /* end x2temp */ echo $form->errorSummary($model); ?> <div class="span-15" id="form-box" style="position:relative;overflow:hidden;height:700px;"> <?php foreach ($fields as $field) { ?> <?php if ($field->fieldName != "id") { $size = $field->size; $pieces = explode(":", $size);
* technical reasons, the Appropriate Legal Notices must display the words * "Powered by X2Engine". *****************************************************************************************/ Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/activityFeed.js', CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/EnlargeableImage.js', CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/jquery-expander/jquery.expander.js', CClientScript::POS_END); // used for rich editing in new post text field Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/ckeditor/ckeditor.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/ckeditor/adapters/jquery.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/emailEditor.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/multiselect/js/ui.multiselect.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/lib/moment-with-locales.min.js'); $groups = Groups::getUserGroups(Yii::app()->user->getId()); $tempUserList = array(); foreach ($groups as $groupId) { $userLinks = GroupToUser::model()->findAllByAttributes(array('groupId' => $groupId)); foreach ($userLinks as $link) { $user = User::model()->findByPk($link->userId); if (isset($user)) { $tempUserList[] = $user->username; } } } $userList = array_keys(User::getNames()); $tempUserList = array_diff($userList, $tempUserList); $usersGroups = implode(",", $tempUserList); Yii::app()->clientScript->registerScript('setUpActivityFeedManager', "\n\nx2.activityFeed = new x2.ActivityFeed ({\n translations: " . CJSON::encode(array('Unselect All' => Yii::t('app', 'Unselect All'), 'Select All' => Yii::t('app', 'Select All'), 'Uncheck All' => Yii::t('app', 'Uncheck All'), 'Check All' => Yii::t('app', 'Check All'), 'Enter text here...' => Yii::t('app', 'Enter text here...'), 'Broadcast Event' => Yii::t('app', 'Broadcast Event'), 'Make Important' => Yii::t('app', 'Make Important'), 'Broadcast' => Yii::t('app', 'Broadcast'), 'broadcast error message 1' => Yii::t('app', 'Select at least one user to broadcast to'), 'broadcast error message 2' => Yii::t('app', 'Select at least one broadcast method'), 'Okay' => Yii::t('app', 'Okay'), 'Nevermind' => Yii::t('app', 'Cancel'), 'Create' => Yii::t('app', 'Create'), 'Cancel' => Yii::t('app', 'Cancel'), 'Read more' => Yii::t('app', 'Read') . ' ' . Yii::t('app', 'More'), 'Read less' => Yii::t('app', 'Read') . ' ' . Yii::t('app', 'Less'))) . ",\n usersGroups: '" . $usersGroups . "',\n minimizeFeed: " . (Yii::app()->params->profile->minimizeFeed == 1 ? 'true' : 'false') . ",\n commentFlag: false,\n lastEventId: " . (!empty($lastEventId) ? $lastEventId : 0) . ",\n lastTimestamp: " . (!empty($lastTimestamp) ? $lastTimestamp : 0) . ",\n profileId: " . $profileId . ",\n myProfileId: " . Yii::app()->params->profile->id . ",\n deletePostUrl: '" . $this->createUrl('/profile/deletePost') . "'\n});\n\n", CClientScript::POS_END); ?> <div id='activity-feed-container' class='x2-layout-island'> <div id='page-title-container'>
public function afterDelete() { // delete related social records (e.g. notes) $social = Social::model()->findAllByAttributes(array('user' => $this->username)); foreach ($social as $socialItem) { $socialItem->delete(); } $social = Social::model()->findAllByAttributes(array('associationId' => $this->id)); foreach ($social as $socialItem) { $socialItem->delete(); } X2CalendarPermissions::model()->deleteAllByAttributes(array(), 'user_id=:userId OR other_user_id=:userId', array(':userId' => $this->id)); // delete profile $prof = Profile::model()->findByAttributes(array('username' => $this->username)); if ($prof) { $prof->delete(); } // delete associated events Yii::app()->db->createCommand()->delete('x2_events', "user=:username OR (type='feed' AND associationId=" . $this->id . ")", array(':username' => $this->username)); // Delete associated group to user records GroupToUser::model()->deleteAll(array('condition' => 'userId=' . $this->id)); parent::afterDelete(); }
/** * 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); $groups = array(); foreach (Groups::model()->findAll() as $group) { $groups[$group->id] = CHtml::encode($group->name); } $selectedGroups = array(); foreach (GroupToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $selectedGroups[] = $link->groupId; } $roles = array(); foreach (Roles::model()->findAll() as $role) { $roles[$role->id] = CHtml::encode($role->name); } $selectedRoles = array(); foreach (RoleToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $selectedRoles[] = $link->roleId; } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (!isset($model->userAlias)) { $model->userAlias = $model->username; } if (isset($_POST['User'])) { $old = $model->attributes; $temp = $model->password; $model->attributes = $_POST['User']; if ($model->password != "") { $model->password = PasswordUtil::createHash($model->password); } else { $model->password = $temp; } if (empty($model->userKey)) { $model->userKey = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 32)), 0, 32); } if ($model->save()) { $profile = $model->profile; if (!empty($profile)) { $profile->emailAddress = $model->emailAddress; $profile->fullName = $model->firstName . ' ' . $model->lastName; $profile->save(); } if ($old['username'] != $model->username) { $fieldRecords = Fields::model()->findAllByAttributes(array('fieldName' => 'assignedTo')); $modelList = array(); foreach ($fieldRecords as $record) { $modelList[$record->modelName] = $record->linkType; } foreach ($modelList as $modelName => $type) { if ($modelName == 'Quotes') { $modelName = "Quote"; } if ($modelName == 'Products') { $modelName = 'Product'; } if (empty($type)) { $list = X2Model::model($modelName)->findAllByAttributes(array('assignedTo' => $old['username'])); foreach ($list as $item) { $item->assignedTo = $model->username; $item->save(); } } else { $list = X2Model::model($modelName)->findAllBySql("SELECT * FROM " . X2Model::model($modelName)->tableName() . " WHERE assignedTo LIKE '%" . $old['username'] . "%'"); foreach ($list as $item) { $assignedTo = explode(", ", $item->assignedTo); $key = array_search($old['username'], $assignedTo); if ($key >= 0) { $assignedTo[$key] = $model->username; } $item->assignedTo = implode(", ", $assignedTo); $item->save(); } } } $profile = Profile::model()->findByAttributes(array('username' => $old['username'])); if (isset($profile)) { $profile->username = $model->username; $profile->save(); } } foreach (RoleToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $link->delete(); } foreach (GroupToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $link->delete(); } if (isset($_POST['roles'])) { $roles = $_POST['roles']; foreach ($roles as $role) { $link = new RoleToUser(); $link->roleId = $role; $link->type = "user"; $link->userId = $model->id; $link->save(); } } if (isset($_POST['groups'])) { $groups = $_POST['groups']; foreach ($groups as $group) { $link = new GroupToUser(); $link->groupId = $group; $link->userId = $model->id; $link->username = $model->username; $link->save(); } } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'groups' => $groups, 'roles' => $roles, 'selectedGroups' => $selectedGroups, 'selectedRoles' => $selectedRoles)); }
public static function getEditableCalendarNames() { $calendars = X2Calendar::model()->findAll(); foreach ($calendars as $key => $calendar) { if ($calendar->googleCalendar && !$calendar->googleCalendarId) { unset($calendars[$key]); } } $names = array(); foreach ($calendars as $calendar) { $editPermissions = explode(',', $calendar->editPermission); if (in_array(Yii::app()->user->name, $editPermissions)) { // current user has permission to view calendar? $names["{$calendar->id}"] = $calendar->name; } else { if (Yii::app()->user->name == 'admin' || Yii::app()->user->name == $calendar->createdBy) { // current user created this calendar? $names["{$calendar->id}"] = $calendar->name; } else { // check if user belongs to a group that can view this calendar foreach ($editPermissions as $permission) { if (is_numeric($permission)) { $groups = GroupToUser::model()->findAllByAttributes(array('groupId' => $permission)); foreach ($groups as $group) { if (Yii::app()->user->id == $group->userId) { $names["{$calendar->id}"] = $calendar->name; } } } } } } } return $names; }
public function testAfterDelete() { $group = Groups::model()->findByPk('1'); VERBOSE_MODE && (print 'id of group to delete: '); VERBOSE_MODE && (print $group->id); // assert that group to user records exist for this group $this->assertTrue(sizeof(GroupToUser::model()->findByAttributes(array('groupId' => $group->id))) > 0); $group->delete(); // assert that group to user records were deleted $this->assertTrue(sizeof(GroupToUser::model()->findByAttributes(array('groupId' => $group->id))) === 0); }
/** * 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); $groups = array(); foreach (Groups::model()->findAll() as $group) { $groups[$group->id] = $group->name; } $selectedGroups = array(); foreach (GroupToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $selectedGroups[] = $link->groupId; } $roles = array(); foreach (Roles::model()->findAll() as $role) { $roles[$role->id] = $role->name; } $selectedRoles = array(); foreach (RoleToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $selectedRoles[] = $link->roleId; } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $temp = $model->password; $model->attributes = $_POST['User']; if ($model->password != "") { $model->password = md5($model->password); } else { $model->password = $temp; } if ($model->save()) { foreach (RoleToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $link->delete(); } foreach (GroupToUser::model()->findAllByAttributes(array('userId' => $model->id)) as $link) { $link->delete(); } if (isset($_POST['roles'])) { $roles = $_POST['roles']; foreach ($roles as $role) { $link = new RoleToUser(); $link->roleId = $role; $link->userId = $model->id; $link->save(); } } if (isset($_POST['groups'])) { $groups = $_POST['groups']; foreach ($groups as $group) { $link = new GroupToUser(); $link->groupId = $group; $link->userId = $model->id; $link->username = $model->username; $link->save(); } } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'groups' => $groups, 'roles' => $roles, 'selectedGroups' => $selectedGroups, 'selectedRoles' => $selectedRoles)); }
public function getRoutingRules($data) { $admin =& Yii::app()->params->admin; //Admin::model()->findByPk(1); $online = $admin->onlineOnly; x2base::cleanUpSessions(); $sessions = Session::getOnlineUsers(); $rules = CActiveRecord::model('LeadRouting')->findAll("", array('order' => 'priority')); foreach ($rules as $rule) { $arr = LeadRouting::parseCriteria($rule->criteria); $flagArr = array(); foreach ($arr as $criteria) { if (isset($data[$criteria['field']])) { $val = $data[$criteria['field']]; $operator = $criteria['comparison']; $target = $criteria['value']; if ($operator != 'contains') { switch ($operator) { case '>': $flag = $val >= $target; break; case '<': $flag = $val <= $target; break; case '=': $flag = $val == $target; break; case '!=': $flag = $val != $target; break; default: $flag = false; } } else { $flag = preg_match("/{$target}/i", $val) != 0; } $flagArr[] = $flag; } } if (!in_array(false, $flagArr) && count($flagArr) > 0) { $users = $rule->users; $users = explode(", ", $users); if (is_null($rule->groupType)) { if ($online == 1) { $users = array_intersect($users, $sessions); } } else { $groups = $rule->users; $groups = explode(", ", $groups); $users = array(); foreach ($groups as $group) { if ($rule->groupType == 0) { $links = GroupToUser::model()->findAllByAttributes(array('groupId' => $group)); foreach ($links as $link) { if (array_search(User::model()->findByPk($link->userId)->username, $users) === false) { $users[] = User::model()->findByPk($link->userId)->username; } } } else { $users[] = $group; } } if ($online == 1 && $rule->groupType == 0) { $users = array_intersect($users, $sessions); } } $users[] = $rule->rrId; $rule->rrId++; $rule->save(); return $users; } } }