public function loadModel($id) { $model = Docs::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
private function ini() { if (!$this->ini) { $this->_precision = Yii::app()->user->getSetting('company.precision'); $this->iVatRate = Item::model()->findByPK($this->item_id)->vat; $this->rate = Currates::model()->GetRate($this->currency_id); if ($this->doc_rate == 0) { $doc = Docs::model()->findByPk($this->doc_id); $this->doc_rate = Currates::model()->GetRate($doc->currency_id); } $this->ini != $this->ini; } }
/** * Magic getter for {@link templateModel} * @return type */ public function getTemplateModel($id = null) { $newTemp = !empty($id); if ($newTemp) { $this->template = $id; $this->_templateModel = null; } else { $id = $this->template; } if (empty($this->_templateModel)) { $this->_templateModel = Docs::model()->findByPk($id); } return $this->_templateModel; }
/** * Echoes 'true' if User has permission, 'false' otherwise * @param int id id of doc model */ public function actionAjaxCheckEditPermission($id) { if (!isset($id)) { echo 'failure'; return; } $doc = Docs::model()->findByPk($id); if (isset($doc)) { $canEdit = $doc->checkEditPermissions() ? 'true' : 'false'; } else { $canEdit = 'false'; } echo $canEdit; return; }
public function make() { $this->id = rand(0, 999999); //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,); //$this->docArr=array(0=>0,305=>0,300=>0,); $bkmv = ''; //$this->line=1; $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec'); $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime'); $from_date = date($phpdbdatetime, CDateTimeParser::parse($this->from_date . ":00", $yiidatetimesec)); $to_date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date . ":00", $yiidatetimesec)); //$types=array(3,4,9,11,13,14); //accounts $criteria = new CDbCriteria(); $accounts = Accounts::model()->findAll($criteria); $record = array('id' => 'B110', 'name' => OpenFormatType::model()->getDesc('B110'), 'count' => 0); foreach ($accounts as $account) { $this->line++; $bkmv .= $account->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; //items $criteria = new CDbCriteria(); $items = Item::model()->findAll($criteria); $record = array('id' => 'M100', 'name' => OpenFormatType::model()->getDesc('M100'), 'count' => 0); foreach ($items as $item) { $this->line++; $bkmv .= $item->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; // //transactions $criteria = new CDbCriteria(); $criteria->condition = "valuedate BETWEEN :from_date AND :to_date"; $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date); $transactions = Transactions::model()->findAll($criteria); $record = array('id' => 'B100', 'name' => OpenFormatType::model()->getDesc('B100'), 'count' => 0); foreach ($transactions as $transaction) { $this->line++; $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; //docs $criteria = new CDbCriteria(); $criteria->condition = "due_date BETWEEN :from_date AND :to_date"; $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date); $docs = Docs::model()->findAll($criteria); //OpenFormatType::model()->getDesc('C100') $record = array('id' => 'C100', 'name' => OpenFormatType::model()->getDesc('C100'), 'count' => 0); $d110 = array('id' => 'D110', 'name' => OpenFormatType::model()->getDesc('D110'), 'count' => 0); $d120 = array('id' => 'D120', 'name' => OpenFormatType::model()->getDesc('D120'), 'count' => 0); foreach ($docs as $doc) { if ($doc->docType->openformat != '0') { $this->line++; $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date); foreach ($doc->docDetailes as $detial) { $this->line++; $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date); $d110['count']++; } foreach ($doc->docCheques as $detial) { $this->line++; $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date); $d120['count']++; } $type = $doc->getType(); $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0; $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total; $record['count']++; } } $this->iniArr[] = $record; $this->iniArr[] = $d110; $this->iniArr[] = $d120; $company = Settings::model()->findByPk('company.name'); //A100 $bkmv = $company->a100(1, $this->id) . $bkmv; //Z900 $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1); $bkmvFile = new Files(); $bkmvFile->name = 'bkmvdata.txt'; $bkmvFile->path = 'openformat/'; // $bkmvFile->expire = 360; $bkmvFile->save(); $bkmvFile->writeFile($bkmv); $this->bkmvId = $bkmvFile->id; //A000 $ini = $company->a000(1, $this->id, $this->line + 1); foreach ($this->iniArr as $line) { $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n"; } //Z $iniFile = new Files(); $iniFile->name = 'ini.txt'; $iniFile->path = 'openformat/'; // $iniFile->expire = 360; $iniFile->save(); $iniFile->writeFile($ini); $this->iniId = $iniFile->id; return $this->id; }
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); }
/** * Renames module * @param string $newTitle * @return bool true for success, false for failure */ public function retitle($newTitle) { $oldTitle = $this->title; $this->title = $newTitle; if ($this->save()) { // if it's a static page, rename the doc too if ($this->name === 'document') { $doc = Docs::model()->findByAttributes(array('name' => $oldTitle)); $doc->name = $this->title; $doc->save(); } // Clear cached display names self::$_displayNames = array(); return true; } else { return false; } }
private function getChildren($option = null) { $children = array('folders' => array(), 'docs' => array()); $folderCriteria = new CDbCriteria(); if ($option === 'root') { $folderCriteria->condition = 'parentFolder IS NULL AND id > 0'; } else { $folderCriteria->compare('parentFolder', $this->id); } $folderCriteria->mergeWith($this->getAccessCriteria()); $folderCriteria->order = 'name ASC'; $children['folders'] = DocFolders::model()->findAll($folderCriteria); $docsCriteria = new CDbCriteria(); $doc = Docs::model(); if ($option === 'root') { $docsCriteria->condition = 'folderId IS NULL AND type NOT IN ("email","quote")'; } elseif ($option === self::TEMPLATES_FOLDER_ID) { $docsCriteria->condition = 'folderId IS NULL AND type IN ("email","quote")'; } else { $docsCriteria->compare('folderId', $this->id); } $docsCriteria->mergeWith($doc->getAccessCriteria()); $docsCriteria->order = 'name ASC'; $children['docs'] = Docs::model()->findAll($docsCriteria); return $children; }
public function actionDeleteFileFolder() { if (Yii::app()->request->isAjaxRequest && isset($_POST['type'], $_POST['id'])) { if ($_POST['type'] === 'folder') { $model = DocFolders::model()->findByPk($_POST['id']); if (is_null($model)) { throw new CHttpException(404, 'Folder not found.'); } if (!$model->checkRecursiveDeletePermissions()) { $this->denied(); } } elseif ($_POST['type'] === 'doc') { $model = Docs::model()->findByPk($_POST['id']); if (is_null($model)) { throw new CHttpException(404, 'File not found.'); } if (!$this->checkPermissions($model, 'delete')) { $this->denied(); } } else { throw new CHttpException(400, 'Bad request.'); } $model->delete(); } else { throw new CHttpException(400, 'Bad request.'); } }
<?php /* * ********************************************************************************* * The contents of this file are subject to the Mozilla Public License Version 2.0 * ("License"); You may not use this file except in compliance with the Mozilla Public License Version 2.0 * The Original Code is: Linet 3.0 Open Source * The Initial Developer of the Original Code is Adam Ben Hur. * All portions are Copyright (C) Adam Ben Hur. * All Rights Reserved. * ********************************************************************************** */ // this is the date picker $dateisOn = $this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'Docs[issue_from]', 'language' => substr(Yii::app()->language, 0, 2), 'value' => $model->issue_from, 'options' => array('showAnim' => 'fold', 'dateFormat' => Yii::app()->locale->getDateFormat('short'), 'changeMonth' => 'true', 'changeYear' => 'true', 'constrainInput' => 'false'), 'htmlOptions' => array('placeholder' => Yii::t('app', 'From Date'))), true) . $this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'Docs[issue_to]', 'language' => substr(Yii::app()->language, 0, 2), 'value' => $model->issue_to, 'options' => array('showAnim' => 'fold', 'dateFormat' => Yii::app()->locale->getDateFormat('short'), 'changeMonth' => 'true', 'changeYear' => 'true', 'constrainInput' => 'false'), 'htmlOptions' => array('placeholder' => Yii::t('app', 'To Date'))), true); ?> <?php $filter = ''; if ($model->doctype != null) { $filter = CHtml::listData(Docstatus::model()->findAllByAttributes(array('doc_type' => $model->doctype)), 'num', 'name'); } else { $model->status = null; } //print_r(Yii::app()->locale); $this->widget('EExcelView', array('id' => 'Docs', 'dataProvider' => $model->search(), 'filter' => $model, 'ajaxUpdate' => true, 'ajaxType' => 'POST', 'afterAjaxUpdate' => "function() {\n\t\t\t\t\t\tjQuery('#Docs_issue_from').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['" . substr(Yii::app()->language, 0, 2) . "'], {'showAnim':'fold','dateFormat':'" . Yii::app()->locale->getDateFormat('short') . "','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));\n\t\t\t\t\t\tjQuery('#Docs_issue_to').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['" . substr(Yii::app()->language, 0, 2) . "'], {'showAnim':'fold','dateFormat':'" . Yii::app()->locale->getDateFormat('short') . "','changeMonth':'true','showButtonPanel':'true','changeYear':'true','constrainInput':'false'}));\n }", 'columns' => array(array('name' => 'doctype', 'filter' => Doctype::model()->getList(), 'value' => '$data->getTypeName()', 'htmlOptions' => array('style' => 'width:20%;')), array('name' => 'status', 'filter' => $filter, 'value' => '$data->getStatus()'), array('name' => 'refstatus', 'filter' => CHtml::listData(Docs::model()->getRefStatuses(), 'id', 'name'), 'value' => '$data->getRefStatus()'), array('name' => 'docnum', 'htmlOptions' => array('style' => 'width:8%;')), array('name' => 'account_id', 'htmlOptions' => array('style' => 'width:8%;')), 'company', array('name' => 'issue_date', 'filter' => $dateisOn, 'value' => '$data->issue_date', 'htmlOptions' => array('style' => 'width:15%;')), array('name' => 'total', 'htmlOptions' => array('style' => 'width:8%;')), array('class' => 'bootstrap.widgets.TbButtonColumn', 'htmlOptions' => array('style' => 'width:80px'), 'template' => '{duplicate}{print}{edit}{delete}{display}', 'buttons' => array('duplicate' => array('label' => '<i class="glyphicon glyphicon-plus-sign"></i>', 'url' => 'Yii::app()->createUrl("docs/duplicate/". $data->id)'), 'edit' => array('label' => '<i class="glyphicon glyphicon-edit"></i>', 'url' => 'Yii::app()->createUrl("docs/update", array("id"=>$data->id))'), 'delete' => array('label' => '<i class="glyphicon glyphicon-remove"></i>', 'deleteConfirmation' => true, 'imageUrl' => false, 'url' => 'Yii::app()->createUrl("docs/delete", array("id"=>$data->id))'), 'print' => array('label' => '<i class="glyphicon glyphicon-print"></i>', 'url' => 'Yii::app()->createUrl("docs/print", array("id"=>$data->id))', 'options' => array("target" => "_blank")), 'display' => array('label' => '<i class="glyphicon glyphicon-search"></i>', 'url' => 'Yii::app()->createUrl("docs/view", array("id"=>$data->id))'))))));
public function init() { $this->disableTemplates = $this->disableTemplates || in_array($this->associationType, array_keys(Docs::modelsWhichSupportEmailTemplates())); // Prepare the model for initially displayed input: $this->model = new InlineEmail(); if (isset($this->targetModel)) { $this->model->targetModel = $this->targetModel; } if (!$this->associationType) { $this->associationType = X2Model::getModelName(Yii::app()->controller->module->name); } // Bring in attributes set in the configuration: $this->model->attributes = $this->attributes; if (empty($this->template)) { // check for a default template $defaultTemplateId = Yii::app()->params->profile->getDefaultEmailTemplate(Yii::app()->controller->module->name); // if there's a default set for this module if ($defaultTemplateId !== null) { $defaultTemplateDoc = Docs::model()->findByPk($defaultTemplateId); // ensure that template is still a valid default if ($defaultTemplateDoc && ($defaultTemplateDoc->associationType === $this->associationType || $defaultTemplateDoc->type === 'quote' && $this->model->targetModel instanceof Quote)) { $this->template = $defaultTemplateId; } } } if (empty($this->template)) { if (empty($this->model->message)) { $this->model->message = InlineEmail::emptyBody(); } $this->model->insertSignature(); } else { // Fill in the body with a template: $this->model->scenario = 'template'; if (!empty($this->template)) { $this->model->template = $this->template; } $this->model->prepareBody(); } // If insertable attributes aren't set, use the inline email model's // getInsertableAttributes() method to generate them. if ((bool) $this->model->targetModel && !isset($this->insertableAttributes)) { $this->insertableAttributes = $this->model->insertableAttributes; } $this->registerJSClassInstantiation(); // Load resources: 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()->getBaseUrl() . '/js/emailEditor.js'); if (!empty($this->insertableAttributes)) { Yii::app()->clientScript->registerScript('setInsertableAttributes', 'x2.insertableAttributes = ' . CJSON::encode($this->insertableAttributes) . ';', CClientScript::POS_HEAD); } Yii::app()->clientScript->registerScript('storeOriginalInlineEmailMessage', 'x2.inlineEmailOriginalBody = $("#email-message").val();', CClientScript::POS_READY); //'.CJSON::encode($this->model->message).';',CClientScript::POS_READY); Yii::app()->clientScript->registerScript('toggleEmailForm', $this->startHidden ? "window.hideInlineEmail = true;\n" : "window.hideInlineEmail = false;\n", CClientScript::POS_HEAD); $this->registerPackages(); parent::init(); }
public function actionIndex() { $docs = Docs::model()->with("Students")->findAll(); $this->render("index", array("docs" => $docs)); }
public function refnumDocsLink() { $str = ''; $array = explode(",", $this->refnum1); foreach ($array as $docid) { $doc = Docs::model()->findByPk($docid); if ($doc !== null) { $str .= CHtml::link(CHtml::encode(Yii::t('app', $doc->docType->name) . " #" . $doc->docnum), Yii::app()->createAbsoluteUrl("/docs/view/{$docid}")); } else { $str .= $docid; } $str .= ","; //echo $docid; } return rtrim($str, ","); }
public function saveRef($id, $total) { $str = $this->refnum; //save new values $sum = 0; $tmp = explode(",", rtrim($str, ",")); foreach ($tmp as $id) { //lets do this //if($id==$this->id){ // throw new CHttpException(500,Yii::t('app','You cannot save doc as a refnum')); //} $doc = Docs::model()->findByPk((int) $id); if ($doc !== null) { $sum += $doc->total; //adam: need to multi currency! if ($sum <= $total) { $doc->refstatus = Docs::STATUS_CLOSED; } else { $doc->refstatus = Docs::STATUS_OPEN; } $doc->refnum = $id; $doc->save(); } } //$this->refnum=$str; }
/** * @param array $gvSelection array of ids of records to perform mass action on */ public function execute(array $gvSelection) { if (Yii::app()->controller->modelClass !== 'Docs' || count($gvSelection) > 1 || !isset($_POST['selectedObjs']) || !is_array($_POST['selectedObjs']) || count($_POST['selectedObjs']) !== count($gvSelection) || !isset($_POST['selectedObjTypes']) || !is_array($_POST['selectedObjTypes']) || count($_POST['selectedObjTypes']) !== count($gvSelection) || !in_array($_POST['selectedObjTypes'][0], array('doc', 'folder')) || !isset($_POST['newName'])) { throw new CHttpException(400, Yii::t('app', 'Bad Request')); } $selectedObjId = array_pop($_POST['selectedObjs']); $type = array_pop($_POST['selectedObjTypes']); $newName = $_POST['newName']; if ($type === 'doc') { $obj = Docs::model()->findByPk($selectedObjId); } else { // $type === 'folder' $obj = DocFolders::model()->findByPk($selectedObjId); } if (!$obj) { self::$errorFlashes[] = Yii::t('app', 'Selected {type} does not exist', array('{type}' => $type === 'doc' ? ucfirst($type) : $type)); return 0; } if (!Yii::app()->controller->checkPermissions($obj, 'edit')) { self::$errorFlashes[] = Yii::t('app', 'You do not have permission to edit this {type}.', array('{type}' => $type === 'doc' ? ucfirst($type) : $type)); return 0; } if ($type === 'doc' && !Yii::app()->params->isAdmin && !in_array('name', Docs::model()->getEditableAttributeNames())) { self::$errorFlashes[] = Yii::t('app', 'You do not have permission to rename Docs.'); return 0; } $obj->name = $newName; $successes = 0; if ($obj->save(true, array('name'))) { self::$successFlashes[] = Yii::t('app', 'Renamed {type}', array('{type}' => $type === 'doc' ? ucfirst($type) : $type)); $successes = 1; } else { self::$errorFlashes[] = Yii::t('app', 'Failed to renamed {type}', array('{type}' => $type === 'doc' ? ucfirst($type) : $type)); } return $successes; }
public function make() { $text = ''; $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec'); $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime'); $from_date = date($phpdbdatetime, CDateTimeParser::parse($this->from_date . ":00", $yiidatetimesec)); $to_date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date . ":00", $yiidatetimesec)); $types = array(3, 4, 9, 11, 13, 14); $criteria = new CDbCriteria(); $criteria->condition = "issue_date BETWEEN :from_date AND :to_date"; $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date); $criteria->compare('doctype', $types); $docs = Docs::model()->findAll($criteria); $vatper = 18; $start = array('t_wovat' => 0, 't_vat' => 0, 'ns_t_wovat' => 0, 'ns_t_vat' => 0, 'i_doc_count' => 0, 't_exclude_vat' => 0, 'ot_vat' => 0, 'at_vat' => 0, 'o_doc_count' => 0, 'sum' => 0); foreach ($docs as $doc) { $text .= $doc->pcn874() . "\n"; if (in_array($doc->doctype, array(3, 4, 9, 11))) { if ($doc->sub_total != 0) { if ($doc->vat / $doc->sub_total * 100 == $vatper) { $start['t_wovat'] += $doc->sub_total; $start['t_vat'] += $doc->vat; } else { if ($doc->vat == 0) { $start['t_exclude_vat'] += $doc->sub_total; } else { $start['ns_t_wovat'] += $doc->sub_total; $start['ns_t_vat'] += $doc->vat; } } } $start['i_doc_count']++; } if (in_array($doc->doctype, array(13, 14))) { if ($doc->doctype == 13) { $start['ot_vat'] += $doc->vat; } else { $start['at_vat'] += $doc->vat; } $start['o_doc_count']++; } } $start['sum'] = $start['t_vat'] + $start['ns_t_vat']; return $this->start($start) . "\n" . $text . $this->end(); }
private function globalExport() { $file='file.csv'; $fp = fopen($file, 'w+'); $users=UserChild::model()->findAll(); $contacts=ContactChild::model()->findAll(); $actions=ActionChild::model()->findAll(); $sales=SaleChild::model()->findAll(); $accounts=AccountChild::model()->findAll(); $docs=Docs::model()->findAll(); $profiles=Profile::model()->findAll(); fputcsv($fp,array("0.9.1")); $userList=array(); foreach($users as $user) { $userList[]=$user->attributes; } foreach ($userList as $fields) { unset($fields['id']); unset($fields['updatePassword']); $fields[]='user'; fputcsv($fp, $fields); } $contactList=array(); foreach($contacts as $contact) { $contactList[]=$contact->attributes; } foreach ($contactList as $fields) { unset($fields['id']); $fields[]='contact'; fputcsv($fp, $fields); } $actionList=array(); foreach($actions as $action) { $actionList[]=$action->attributes; } foreach ($actionList as $fields) { unset($fields['id']); $fields[]='action'; fputcsv($fp, $fields); } $saleList=array(); foreach($sales as $sale) { $saleList[]=$sale->attributes; } foreach ($saleList as $fields) { unset($fields['id']); $fields[]='sale'; fputcsv($fp, $fields); } $accountList=array(); foreach($accounts as $account) { $accountList[]=$account->attributes; } foreach ($accountList as $fields) { unset($fields['id']); $fields[]='account'; fputcsv($fp, $fields); } $docList=array(); foreach($docs as $doc) { $docList[]=$doc->attributes; } foreach ($docList as $fields) { unset($fields['id']); $fields[]='doc'; fputcsv($fp, $fields); } $profileList=array(); foreach($profiles as $profile) { if($profile->username!='admin') $profileList[]=$profile->attributes; } foreach ($profileList as $fields) { unset($fields['id']); unset($fields['avatar']); $fields[]='profile'; fputcsv($fp, $fields); } fclose($fp); }
/** * Saves a default template for the specified module into the users profile settings * @param string $moduleName * @param int $templateId */ public function actionAjaxSaveDefaultEmailTemplate($moduleName, $templateId) { $profile = Yii::app()->params->profile; $errors = false; $message = ''; if (isset($profile)) { $defaultEmailTemplates = CJSON::decode($profile->defaultEmailTemplates); if ($templateId !== '') { $template = Docs::model()->findByPk($templateId); if (!$this->checkPermissions($template, 'view')) { $errors = true; $message = Yii::t('profile', 'You do not have permission to view that template'); } else { // check that template exists, that it's of the correct doc type, and is // associated with the correct model type if ($template && ($template->type === 'email' && $template->associationType === X2Model::getModelName($moduleName) || $template->type === 'quote' && $moduleName === 'quotes')) { $defaultEmailTemplates[$moduleName] = $templateId; $profile->defaultEmailTemplates = CJSON::encode($defaultEmailTemplates); $profile->save(); } else { $errors = true; $message = Yii::t('profile', 'Invalid template'); } } } else { // remove default if (isset($defaultEmailTemplates[$moduleName])) { unset($defaultEmailTemplates[$moduleName]); } $profile->defaultEmailTemplates = CJSON::encode($defaultEmailTemplates); $profile->save(); } } else { $message = Yii::t('profile', 'Profile not found'); } echo CJSON::encode(array('success' => !$errors, 'message' => $message)); }
</ul> </div> </div> <!-- /.col-md-8 --> </div> <!-- /.row --> <br>Презентации <br> <?php echo $form->dropDownList($track, 'Docs', CHtml::listData(Docs::model()->findAll(), 'id', 'title'), array("multiple" => true)); ?> <br>Алгоритмы<br> <?php echo $form->dropDownList($track, 'Algorithms', CHtml::listData(Algorithms::model()->findAll(), 'id', 'title'), array("multiple" => true)); ?> <br><br> <button type="submit" class="btn btn-success btn-lg">Сохранить</button> <?php $this->endWidget(); ?>
public static function getMax($type_id) { $model = new Docs(); $criteria = new CDbCriteria(); $criteria->select = 'max(docnum) AS maxDocnum'; $criteria->condition = "doctype = :type_id"; $criteria->params = array(':type_id' => $type_id); $row = $model->model()->find($criteria); return $row['maxDocnum']; }
$authItem = $auth->getAuthItem($action); $permission = Yii::app()->params->isAdmin || Yii::app()->user->checkAccess($action) || is_null($authItem); if ($file->exists) { if ($permission) { $menuItems[$key] = array('label' => Yii::t('app', $value), 'itemOptions' => array('class' => 'top-bar-module-link'), 'url' => array("/{$key}/{$defaultAction}"), 'active' => strtolower($module) == strtolower($key) ? true : null); } } elseif (is_dir('protected/modules/' . $key)) { if (!is_null($this->getModule())) { $module = $this->getModule()->id; } if ($permission) { $active = strtolower($module) == strtolower($key) && (!isset($_GET['static']) || $_GET['static'] != 'true') ? true : null; $menuItems[$key] = array('label' => Yii::t('app', $value), 'url' => array("/{$key}/{$defaultAction}"), 'itemOptions' => array('class' => 'top-bar-module-link'), 'active' => $active); } } else { $page = Docs::model()->findByAttributes(array('name' => ucfirst(mb_ereg_replace(':', ':', $value)))); if (isset($page) && Yii::app()->user->checkAccess('DocsView')) { $id = $page->id; $menuItems[$key] = array('label' => ucfirst($value), 'url' => array('/docs/' . $id . '?static=true'), 'itemOptions' => array('class' => 'top-bar-module-link'), 'active' => Yii::app()->request->requestUri == $scriptUrl . '/docs/' . $id . '?static=true' ? true : null); } } } $maxMenuItems = 4; //check if menu has too many items to fit nicely $menuItemCount = count($menuItems); if ($menuItemCount > $maxMenuItems) { end($menuItems); //move the last few menu items into the "More" dropdown for ($i = 0; $i < $menuItemCount - ($maxMenuItems - 1); $i++) { $menuItems[key($menuItems)]['itemOptions'] = array('style' => 'display: none;', 'class' => 'top-bar-module-link'); prev($menuItems);
/** * @param array $gvSelection array of ids of records to perform mass action on */ public function execute(array $gvSelection) { if (Yii::app()->controller->modelClass !== 'Docs' || !isset($_POST['selectedObjs']) || !is_array($_POST['selectedObjs']) || count($_POST['selectedObjs']) !== count($gvSelection) || !isset($_POST['selectedObjTypes']) || !is_array($_POST['selectedObjTypes']) || count($_POST['selectedObjTypes']) !== count($gvSelection)) { throw new CHttpException(400, Yii::t('app', 'Bad Request')); } $selectedObjs = $_POST['selectedObjs']; $selectedObjTypes = $_POST['selectedObjTypes']; if (!isset($_POST['targetFolder']) || $_POST['targetFolder'] === '') { $destination = null; } else { $targetFolder = $_POST['targetFolder']; $destination = DocFolders::model()->findByPk($targetFolder); if (!$destination) { throw new CHttpException(400, Yii::t('app', 'Folder not found')); } if (!Yii::app()->controller->checkPermissions($destination, 'edit')) { self::$errorFlashes[] = Yii::t('app', 'You do not have permission to edit this folder.'); return 0; } } $objCount = count($gvSelection); $successes = 0; for ($i = 0; $i < $objCount; $i++) { $id = $selectedObjs[$i]; if ((int) $id === DocFolders::TEMPLATES_FOLDER_ID) { continue; } $type = $selectedObjTypes[$i]; if ($type === 'doc') { $obj = Docs::model()->findByPk($id); } elseif ($type === 'folder') { $obj = DocFolders::model()->findByPk($id); } else { self::$errorFlashes[] = Yii::t('app', 'Invalid object type.'); continue; } if (!$obj) { self::$errorFlashes[] = Yii::t('app', 'Selected {type} does not exist', array('{type}' => $type === 'doc' ? ucfirst($type) : $type)); continue; } if (!Yii::app()->controller->checkPermissions($obj, 'edit')) { self::$errorFlashes[] = Yii::t('app', 'You do not have permission to edit this {type}.', array('{type}' => $type === 'doc' ? ucfirst($type) : $type)); continue; } if ($obj instanceof DocFolders && $destination && $obj->id === $destination->id) { self::$errorFlashes[] = Yii::t('app', 'Cannot move "{name}" to a folder inside itself.', array('{name}' => $obj->name)); continue; } if ($obj->moveTo($destination)) { $successes++; } else { self::$errorFlashes[] = Yii::t('app', 'Failed to move "{name}"', array('{name}' => $obj->name)); } } if ($successes) { self::$successFlashes[] = Yii::t('app', '{n} object moved to "{destination}"|{n} objects moved to "{destination}"', array($successes, '{destination}' => $destination ? $destination->name : Yii::t('docs', 'Docs'))); } return $successes; }
/** * Fix email templates broken by the 5.1->5.2/5.3 media module changes. */ public function actionConvertEmailTemplates() { $status = null; if (isset($_POST['yt0'])) { $docs = Docs::model()->findAllByAttributes(array('type' => 'email')); $converted = 0; foreach ($docs as $doc) { $changed = false; preg_match_all('|<img(.*?)src="(.*?)"(.*?)/?>|ism', $doc->text, $matches); $serverBasePath = Yii::app()->request->getServerName() . Yii::app()->baseUrl; foreach ($matches[2] as $filePath) { if (strpos($filePath, $serverBasePath) !== false) { $uploadPath = str_replace($serverBasePath, '', $filePath); $pieces = explode('/', $uploadPath); $fileName = $pieces[sizeof($pieces) - 1]; $mediaObj = Media::model()->findByAttributes(array('fileName' => $fileName)); if (isset($mediaObj)) { $doc->text = preg_replace('|<img(.*?)src="' . preg_quote($filePath) . '"(.*?)/?>|ism', '<img\\1src="' . $mediaObj->getPublicUrl() . '"\\2/>', $doc->text); $changed = true; } } } if ($changed) { $doc->save(); $converted++; } } $status = $converted; } $this->render('convertEmailTemplates', array('status' => $status)); }
protected function getJSSortableWidgetParams() { if (!isset($this->_JSSortableWidgetParams)) { $docId = self::getJSONProperty($this->profile, 'docId', $this->widgetType, $this->widgetUID); if ($docId !== '') { $doc = Docs::model()->findByPk($docId); } else { $docId = ''; } if (isset($doc)) { $canEdit = $doc->checkEditPermissions() ? 1 : 0; } else { $canEdit = 0; } $this->_JSSortableWidgetParams = array_merge(parent::getJSSortableWidgetParams(), array('getItemsUrl' => Yii::app()->createUrl("/docs/docs/getItems"), 'getDocUrl' => Yii::app()->createUrl("/docs/docs/getItem"), 'enableResizing' => true, 'editDocUrl' => Yii::app()->controller->createAbsoluteUrl('/docs/docs/update'), 'docId' => $docId, 'canEdit' => $canEdit, 'checkEditPermissionUrl' => Yii::app()->controller->createUrl("/docs/docs/ajaxCheckEditPermission"))); } return $this->_JSSortableWidgetParams; }