/** * Load configuration that cannot be put in config/main */ public function beginRequest() { $prof=Profile::model()->findByPk(Yii::app()->user->getId()); if (isset($prof->language)) $this->owner->language=$prof->language; else{ $adminProf=ProfileChild::model()->findByPk(1); $this->owner->language=$adminProf->language; } if(isset($prof->timeZone) && $prof->timeZone!='') date_default_timezone_set($prof->timeZone); $adminProf=ProfileChild::model()->findByAttributes(array('username'=>'admin')); $logo=Media::model()->findByAttributes(array('associationId'=>$adminProf->id,'associationType'=>'logo')); if(isset($logo)){ $this->owner->params->logo=$logo->fileName; } $admin = CActiveRecord::model('Admin')->findByPk(1); $this->owner->params->currency = $admin->currency; }
public function getWidgets() { $model = ProfileChild::model('ProfileChild')->findByPk(Yii::app()->user->getId()); $registeredWidgets = array_keys(Yii::app()->params->registeredWidgets); $widgetNames = ($model->widgetOrder=='')? array() : explode(":",$model->widgetOrder); $visibility = ($model->widgets=='')? array() : explode(":",$model->widgets); $widgetList = array(); $updateRecord = false; for($i=0;$i<count($widgetNames);$i++) { if(!in_array($widgetNames[$i],$registeredWidgets)) { // check the main cfg file unset($widgetNames[$i]); // if widget isn't listed, unset($visibility[$i]); // remove it from database fields $updateRecord = true; } else { $widgetList[$widgetNames[$i]] = array('id'=>'widget_'.$widgetNames[$i],'visibility'=>$visibility[$i]); } } foreach($registeredWidgets as $class) { // check list of widgets in main cfg file if(!in_array($class,array_keys($widgetList))) { // if they aren't in the list, $widgetList[$class] = array('id'=>'widget_'.$class,'visibility'=>1); // add them at the bottom $widgetNames[] = $class; // add new widgets to widgetOrder array $visibility[] = 1; // and visibility array $updateRecord = true; } } if($updateRecord) { $model->widgetOrder = implode(':',$widgetNames); // update database fields $model->widgets = implode(':',$visibility); // if there are new widgets $model->save(); } return $widgetList; }
* specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); Yii::app()->params->profile = ProfileChild::model()->findByPk(1); // jQuery and jQuery UI libraries Yii::app()->clientScript->registerCoreScript('jquery'); Yii::app()->clientScript->registerCoreScript('jquery.ui'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/backgroundImage.js'); // blueprint CSS framework $themeURL = Yii::app()->theme->getBaseUrl(); Yii::app()->clientScript->registerCssFile($themeURL . '/css/screen.css', 'screen, projection'); Yii::app()->clientScript->registerCssFile($themeURL . '/css/print.css', 'print'); Yii::app()->clientScript->registerCssFile($themeURL . '/css/main.css', 'screen, projection'); Yii::app()->clientScript->registerCssFile($themeURL . '/css/form.css', 'screen, projection'); Yii::app()->clientScript->registerScript('checkImages', "\n\$(document).ready(function() {\n\t\$('#main-menu-icon, #footer-logo, #footer-logo img').css({'display':'inline','visibility':'visible','z-index':'2147483647'});\n \n});\n", CClientScript::POS_END); $backgroundImg = ''; $defaultOpacity = 1; $themeCss = ''; $checkResult = false;
public function actionDelete($id) { $model = $this->loadModel($id); if (Yii::app()->request->isPostRequest) { $this->cleanUpTags($model); if (!is_numeric($model->assignedTo)) { // assigned to user $profile = ProfileChild::model()->findByAttributes(array('username' => $model->assignedTo)); $profile->deleteGoogleCalendarEvent($model); // update action in Google Calendar if user has a Google Calendar } $model->delete(); } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (isset($_GET['ajax'])) { echo 'Success'; } else { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } }
public function actionToggleDefaultLogo() { $adminProf=ProfileChild::model()->findByAttributes(array('username'=>'admin')); $logo=Media::model()->findByAttributes(array('associationId'=>$adminProf->id,'associationType'=>'logo')); if(!isset($logo)) { $logo=new Media; $logo->associationType='logo'; $name='yourlogohere.png'; $logo->associationId=$adminProf->id; $logo->fileName='uploads/logos/'.$name; if($logo->save()) { } } else { $logo->delete(); } $this->redirect(array('index')); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model=ProfileChild::model('ProfileChild')->findByPk((int)$id); if($model===null) throw new CHttpException(404,Yii::t('app','The requested page does not exist.')); return $model; }
public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $profile = ProfileChild::model()->findByPk(Yii::app()->user->getId()); // get user's preferred results per page $resultsPerPage = $profile->resultsPerPage; $criteria=new CDbCriteria; $parameters=array('condition'=>"visibility='1' || assignedTo='Anyone' || assignedTo='".Yii::app()->user->getName()."'",'limit'=>ceil(ProfileChild::getResultsPerPage())); $criteria->scopes=array('findAll'=>array($parameters)); $criteria->compare('id',$this->id); $criteria->compare('firstName',$this->firstName,true); $criteria->compare('CONCAT(firstName," ",lastName)',$this->lastName,true); $criteria->compare('title',$this->title,true); $criteria->compare('company',$this->company,true); $criteria->compare('accountId',$this->accountId); $criteria->compare('phone',$this->phone,true); $criteria->compare('phone2',$this->phone2,true); $criteria->compare('email',$this->email,true); $criteria->compare('website',$this->website,true); $criteria->compare('address',$this->address,true); $criteria->compare('city',$this->city,true); $criteria->compare('state',$this->state,true); $criteria->compare('zipcode',$this->zipcode,true); $criteria->compare('country',$this->country,true); $criteria->compare('visibility',$this->visibility); $criteria->compare('assignedTo',$this->assignedTo,true); $criteria->compare('backgroundInfo',$this->backgroundInfo,true); $criteria->compare('twitter',$this->twitter,true); $criteria->compare('linkedin',$this->linkedin,true); $criteria->compare('skype',$this->skype,true); $criteria->compare('googleplus',$this->googleplus,true); $criteria->compare('lastUpdated',$this->lastUpdated,true); $criteria->compare('updatedBy',$this->updatedBy,true); $criteria->compare('priority',$this->priority,true); $criteria->compare('leadSource',$this->leadSource,true); $criteria->compare('rating',$this->rating); $criteria->compare('createDate',$this->createDate); return new SmartDataProvider('Contacts', array( 'sort'=>array( 'defaultOrder'=>'lastUpdated DESC', ), 'pagination'=>array( 'pageSize'=>ProfileChild::getResultsPerPage(), ), 'criteria'=>$criteria, )); }
* - Neither the name of X2Engine or X2CRM nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ $profile = ProfileChild::model()->findByPk(Yii::app()->user->id); $this->showActions = $profile->showActions; if (!$this->showActions) { // if user hasn't saved a type of action to show, show uncomple actions by default $this->showActions = 'uncomplete'; } if ($this->showActions == 'uncomplete') { $model->complete = 'No'; } else { if ($this->showActions == 'complete') { $model->complete = 'Yes'; } else { $model->complete = ''; } } if ($this->route == 'actions/default/index') {
public static function getDetailView() { $model = ProfileChild::model()->findByPk(Yii::app()->user->getId()); // get user's preference for contact detail view return $model->showDetailView; }
/** * Load configuration that cannot be put in config/main */ public function beginRequest() { $t0 = microtime(true); if ($this->owner->request->getPathInfo() == 'notifications/getMessages') { // skip all the loading if this is a chat/notification update $timezone = $this->owner->db->createCommand()->select('timeZone')->from('x2_profile')->where('id=1')->queryScalar(); // set the timezone to the admin's if (!isset($timezone)) { $timezone = 'UTC'; } date_default_timezone_set($timezone); return; } Yii::import('application.controllers.x2base'); Yii::import('application.models.*'); Yii::import('application.components.*'); // Yii::import('application.components.ERememberFiltersBehavior'); // Yii::import('application.components.EButtonColumnWithClearFilters'); // $this->owner->messages->forceTranslation = true; $this->owner->messages->onMissingTranslation = array(new TranslationLogger(), 'log'); $this->owner->params->admin = CActiveRecord::model('Admin')->findByPk(1); $this->owner->params->profile = CActiveRecord::model('ProfileChild')->findByPk($this->owner->user->getId()); // die( var_dump($this->owner->request->getPathInfo())); //->getRoute(); if (!$this->owner->user->isGuest) { // use the admin's profile as default $this->owner->params->profile = CActiveRecord::model('ProfileChild')->findByPk($this->owner->user->getId()); $session = Session::model()->findByAttributes(array('user' => $this->owner->user->getName())); if (isset($session)) { if (time() - $session->lastUpdated > $this->owner->params->admin->timeout) { $session->delete(); $this->owner->user->logout(); } else { $session->lastUpdated = time(); $session->save(); } } else { $this->owner->user->logout(); // $this->redirect(Yii::app()->controller->createUrl('site/logout')); } if (!is_null($this->owner->user->getId()) && $this->owner->user->getName() != 'admin') { $this->owner->params->roles = $this->owner->db->createCommand()->select('roleId')->from('x2_role_to_user')->where('type="user" AND userId=' . $this->owner->user->getId())->queryColumn(); $this->owner->params->groups = $this->owner->db->createCommand()->select('groupId')->from('x2_group_to_user')->where('userId=' . $this->owner->user->getId())->queryColumn(); $groupRoles = Yii::app()->db->createCommand()->select('x2_role_to_user.roleId')->from('x2_group_to_user')->join('x2_role_to_user', 'x2_role_to_user.userId=x2_group_to_user.groupId AND x2_group_to_user.userId="' . Yii::app()->user->getId() . '" AND type="group"')->queryColumn(); // foreach($this->owner->params->groups as $groupId) { // lookup roles for all the user's groups // $groupRoles += $this->owner->db->createCommand() // ->select('roleId') // ->from('x2_role_to_user') // ->where('type="group" AND userId='.$groupId)->queryColumn(); // } $this->owner->params->roles = array_unique($this->owner->params->roles + $groupRoles); // combine all the roles, remove duplicates } } $modules = $this->owner->modules; $arr = array(); foreach (scandir('protected/modules') as $module) { if (file_exists("protected/modules/{$module}/register.php")) { $arr[$module] = ucfirst($module); Yii::import("application.modules.{$module}.models.*"); } } foreach ($arr as $key => $module) { $record = Modules::model()->findByAttributes(array('name' => $key)); if (isset($record) && $record->visible) { $modules[] = $key; } } $this->owner->setModules($modules); $adminProf = ProfileChild::model()->findByPk(1); // set currency $this->owner->params->currency = $this->owner->params->admin->currency; // set language if (!empty($this->owner->params->profile->language)) { $this->owner->language = $this->owner->params->profile->language; } else { if (isset($adminProf)) { $this->owner->language = $adminProf->language; } else { $this->owner->language = ''; } } // set timezone if (!empty($this->owner->params->profile->timeZone)) { date_default_timezone_set($this->owner->params->profile->timeZone); } elseif (!empty($adminProf->timeZone)) { date_default_timezone_set($adminProf->timeZone); } else { date_default_timezone_set('UTC'); } $logo = Media::model()->findByAttributes(array('associationId' => 1, 'associationType' => 'logo')); if (isset($logo)) { $this->owner->params->logo = $logo->fileName; } setlocale(LC_ALL, 'en_US.UTF-8'); // die(microtime(true)-$t0); }
public function actionDeleteAction() { if (isset($_POST['id'])) { $id = $_POST['id']; $action = Actions::model()->findByPk($id); $profile = ProfileChild::model()->findByAttributes(array('username' => $action->assignedTo)); $profile->deleteGoogleCalendarEvent($action); // update action in Google Calendar if user has a Google Calendar $action->delete(); } }
public function actionDelete($id) { $model = $this->loadModel($id); if (Yii::app()->request->isPostRequest) { $dataProvider = new CActiveDataProvider('Actions', array('criteria' => array('condition' => "assignedTo='{$model->username}'"))); $actions = $dataProvider->getData(); foreach ($actions as $action) { if ($action->updatedBy == $model->username) { $action->updatedBy = 'admin'; } if ($action->completedBy == $model->username) { $action->completedBy = 'admin'; } $action->assignedTo = "Anyone"; $action->save(); } $dataProvider = new CActiveDataProvider('Contacts', array('criteria' => array('condition' => "assignedTo='{$model->username}'"))); $contacts = $dataProvider->getData(); foreach ($contacts as $contact) { if ($contact->updatedBy == $model->username) { $contact->updatedBy = 'admin'; } if ($contact->completedBy == $model->username) { $contact->completedBy = 'admin'; } $contact->assignedTo = "Anyone"; $contact->save(); } $prof = ProfileChild::model()->findByAttributes(array('username' => $model->username)); $prof->delete(); $model->delete(); } else { throw new CHttpException(400, Yii::t('app', 'Invalid request. Please do not repeat this request again.')); } // 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('admin')); } }
private function globalExport() { $file = 'data.csv'; $fp = fopen($file, 'w+'); $modules = Modules::model()->findAll(); $pieces = array(); foreach ($modules as $module) { $pieces[] = $module->name; } $tempArr = array(); foreach ($pieces as $model) { if ($model == "quotes") { $model = "quote"; } if ($model == "products") { $model = "product"; } if ($model == 'marketing') { $model = "campaign"; } if ($model != 'dashboard' && $model != 'calendar' && is_null(Docs::model()->findByAttributes(array('title' => $model)))) { $tempArr[ucfirst($model)] = CActiveRecord::model(ucfirst($model))->findAll(); } } $tempArr['Profile'] = ProfileChild::model()->findAll(); $labels = array(); foreach ($tempArr as $model => $data) { $temp = CActiveRecord::model($model); $tempKeys = array_keys($temp->attributes); $tempKeys[] = $model; $labels[$model] = $tempKeys; } fputcsv($fp, array(Yii::app()->params->version)); $keys = array_keys($tempArr); for ($i = 0; $i < count($tempArr); $i++) { $meta = $labels[$keys[$i]]; fputcsv($fp, $meta); foreach ($tempArr[$keys[$i]] as $data) { $tempAtr = $data->attributes; $tempAtr[] = $keys[$i]; fputcsv($fp, $tempAtr); } } fclose($fp); }
$checkResult = false; $checkFiles = array( 'themes/x2engine/images/x2footer.png'=>'42a673ec030ac4030f4624fa93318812', 'themes/x2engine/images/x2-mini-icon.png'=>'153d66b514bf9fb0d82a7521a3c64f36', ); foreach($checkFiles as $key=>$value) { if(!file_exists($key) || hash_file('md5',$key) != $value) $checkResult = true; } $theme2Css = ''; if($checkResult) $theme2Css = 'html * {background:url('.CHtml::normalizeUrl(array('site/warning')).') !important;} #bg{display:none !important;}'; // get user record $userModel = CActiveRecord::model('ProfileChild')->findByPk(Yii::app()->user->getId()); if(!isset($userModel)) $userModel=ProfileChild::model()->findByPk(1); if (!empty($userModel->pageOpacity)) { $defaultOpacity = $userModel->pageOpacity / 100; Yii::app()->clientScript->registerScript('loadPageOpacity'," $(document).ready(function() { $('#page').fadeTo(0,".$defaultOpacity."); }); ",CClientScript::POS_HEAD); } // check for background image, use it if one is set if(empty($userModel->backgroundImg)) $backgroundImg = CHtml::image('','',array('id'=>'bg','style'=>'display:none;')); else $backgroundImg = CHtml::image(Yii::app()->getBaseUrl().'/uploads/'.$userModel->backgroundImg,'',array('id'=>'bg'));