public function init()
 {
     $this->parts = ZakazParts::model()->findAllByAttributes(['proj_id' => $this->project->id]);
     $this->payments = ProjectPayments::model()->findByAttributes(['order_id' => $this->project->id]);
     $this->changes = ProjectChanges::model()->findAllByAttributes(['project_id' => $this->project->id]);
     $this->messages = ProjectMessages::model()->findAllByAttributes(['order' => $this->project->id], ['order' => 'id DESC']);
 }
 public function init()
 {
     // --- campaign
     $c_id = Campaign::getId();
     if ($c_id) {
         $folder = '/uploads/c' . $c_id . '/parts/';
     } else {
         $folder = '/uploads/additions/';
     }
     // ---
     $this->arrDataProvider = new CArrayDataProvider(ZakazParts::model()->with('files')->findAllByAttributes(['proj_id' => $this->projectId]));
     if (!file_exists(Yii::getPathOfAlias('webroot') . $folder)) {
         mkdir(Yii::getPathOfAlias('webroot') . $folder, 0777, true);
     }
     if (!file_exists(Yii::getPathOfAlias('webroot') . $folder . 'temp/')) {
         mkdir(Yii::getPathOfAlias('webroot') . $folder . 'temp/', 0777);
     }
     if (!User::model()->isCustomer()) {
         foreach (array_diff(scandir(Yii::getPathOfAlias('webroot') . $folder . 'temp/'), array('..', '.')) as $k => $v) {
             $temps[array_reverse(str_getcsv(pathinfo($v, PATHINFO_FILENAME), '_'))[0]][$k] = array('id' => 0, 'part_id' => array_reverse(str_getcsv(pathinfo($v, PATHINFO_FILENAME), '_'))[0], 'orig_name' => implode('_', array_slice(str_getcsv(pathinfo($v, PATHINFO_FILENAME), '_'), 0, -1)) . '.' . pathinfo($v, PATHINFO_EXTENSION), 'file_name' => Yii::app()->baseUrl . $folder . 'temp/' . $v, 'comment' => 0, 'for_approved' => 'Must approved');
         }
     }
     $tempdata = $this->arrDataProvider->getData();
     foreach ($tempdata as $k => $v) {
         if (isset($tempdata[$k]->files)) {
             foreach ($tempdata[$k]->files as $fk => $fv) {
                 $tempdata[$k]->files[$fk]->file_name = Yii::app()->baseUrl . $folder . $fv->part_id . '/' . $fv->file_name;
             }
         }
         if (isset($temps[$v->id])) {
             $tempdata[$k]->files = array_merge($v->files, $temps[$v->id]);
         }
     }
     $this->arrDataProvider->setData($tempdata);
 }
 public function init()
 {
     // --- Организации
     $c_id = Campaign::getId();
     if ($c_id) {
         Payment::$table_prefix = $c_id . '_';
         //Profile::$table_prefix = $c_id.'_';
         //ProfileField::$table_prefix = $c_id.'_';
         ProjectChanges::$table_prefix = $c_id . '_';
         ProjectChanges::$file_path = 'uploads/c' . $c_id . '/changes_documents';
         //ProjectMessages::$table_prefix = $c_id.'_';
         ProjectPayments::$table_prefix = $c_id . '_';
         Zakaz::$table_prefix = $c_id . '_';
         Zakaz::$files_folder = '/uploads/c' . $c_id . '/';
         Events::$table_prefix = $c_id . '_';
         ZakazParts::$table_prefix = $c_id . '_';
         UpdateProfile::$table_prefix = $c_id . '_';
         ZakazPartsFiles::$table_prefix = $c_id . '_';
         PaymentImage::$table_prefix = $c_id . '_';
         Emails::$table_prefix = $c_id . '_';
         Yii::app()->language = Campaign::getLanguage();
     } else {
         ProjectChanges::$file_path = 'uploads/changes_documents';
     }
     // ---
     if (!Yii::app()->user->isGuest) {
         switch (User::model()->getUserRole()) {
             case 'Manager':
             case 'Admin':
                 Yii::app()->theme = 'admin';
                 break;
             case 'Author':
                 $this->menu = array(array('label' => Yii::t('site', 'My orders'), 'url' => array('/project/zakaz/ownList')), array('label' => Yii::t('site', 'New projects'), 'url' => array('/project/zakaz/list')), array('label' => Yii::t('site', 'Profile'), 'url' => array('/user/profile/edit')), array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 $this->authMenu = array(array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 Yii::app()->theme = 'client';
                 break;
             case 'Customer':
                 $this->menu = array(array('label' => Yii::t('site', 'My orders'), 'url' => array('/project/zakaz/customerOrderList')), array('label' => Yii::t('site', 'Create order'), 'url' => array('/project/zakaz/create')), array('label' => Yii::t('site', 'Profile'), 'url' => array('/user/profile/edit')), array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 $this->authMenu = array(array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 Yii::app()->theme = 'client';
                 break;
         }
     }
     //		var_dump(Yii::app()->controller->module->id ,Yii::app()->controller->id, Yii::app()->controller->action->id);
     //		die();
 }
</div>
<?php 
$this->breadcrumbs = array(ProjectModule::t('Zakazs'));
$columns = array('id');
$columns[] = array('name' => 'title');
if (ProjectField::model()->inTableByVarname('specials')) {
    $columns[] = array('name' => 'specials', 'filter' => Catalog::getAll('specials'), 'value' => '$data->catalog_specials->cat_name');
}
if (ProjectField::model()->inTableByVarname('specials2')) {
    $columns[] = array('name' => 'specials2', 'filter' => Catalog::getAll('specials2'), 'value' => '$data->catalog_specials2->cat_name');
}
$columns[] = array('name' => 'max_exec_date', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'dbmax_exec_date', 'language' => Yii::app()->language), true), 'value' => '$data->dbmax_exec_date');
$columns[] = array('name' => 'author_informed', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'dbauthor_informed', 'language' => Yii::app()->language), true), 'value' => '$data->dbauthor_informed');
$columns[] = array('name' => 'manager_informed', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'dbmanager_informed', 'language' => Yii::app()->language), true), 'value' => '$data->dbmanager_informed');
$columns[] = array('name' => 'status', 'filter' => ProjectStatus::getAll(), 'value' => '$data->statusName');
$columns[] = array('name' => 'lastPartStatus', 'filter' => ZakazParts::model()->getForFilter(), 'value' => '$data->lastPartStatus');
$columns[] = array('name' => 'lastPartDate', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'lastPartDate', 'language' => Yii::app()->language), true), 'value' => '$data->lastPartDate');
if (ProjectField::model()->inTableByVarname('technicalspec')) {
    $columns[] = array('name' => 'technicalspec', 'value' => '$data->technicalspec == 1 ? ProjectModule::t(\'Yes\') : ProjectModule::t(\'No\')', 'filter' => array("0" => ProjectModule::t('No'), "1" => ProjectModule::t('Yes')));
}
$columns[] = array('class' => 'CButtonColumn', 'template' => '{delete}{update}');
/*
$projectFields = $model->getFields();
if ($projectFields) {
	foreach($projectFields as $field) {
		if ($field->field_type=="LIST"){
			$varname = $field->varname;
			$arr = Catalog::getAll($varname);
			if (!$arr) $arr = Catalog::getAll($varname, 0); // Если список одноуровненвый
			$columns[] = array(
					'name'=>$varname,
 public function actionUpload()
 {
     $folder = $this->folder();
     $this->_prepairJson();
     $folder = $_SERVER['DOCUMENT_ROOT'] . $folder;
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     //chmod($folder, 0777);     // !-----------------------------DeBuG oNlY !!-----------------------------------------
     $folder = $folder . 'temp/';
     //chmod($folder, 0777);     // !-----------------------------DeBuG oNlY !!-----------------------------------------
     $config['allowedExtensions'] = array('jpg', 'jpeg', 'png', 'gif', 'txt', 'doc', 'docx');
     $config['disAllowedExtensions'] = array("exe, php");
     $sizeLimit = 10 * 1024 * 1024;
     $pi = pathinfo($_GET['qqfile']);
     $_GET['qqfile'] = $pi['filename'] . '_' . $_GET['id'] . '.' . $pi['extension'];
     $uploader = new qqFileUploader($config, $sizeLimit);
     $this->result = $uploader->handleUpload($folder, true);
     if ($this->result['success']) {
         $part = ZakazParts::model()->findByPk($_GET['id']);
         if (!User::model()->isManager()) {
             EventHelper::partDone($_GET['proj_id'], $part->title);
         }
     }
     chmod($folder . $_GET['qqfile'], 0666);
     if (User::model()->isManager() || User::model()->isAdmin()) {
         $this->_file_data['part_id'] = $_GET['id'];
         $this->_file_data['orig_name'] = $pi['filename'] . '.' . $pi['extension'];
         $this->_file_data['id'] = 0;
         $this->_file_data['req'] = 1;
         $this->actionApiApprove();
     }
     //$this->result['html']='=)';//'<li>!!!<a href="' . $this->result['file_name'] . '" id="parts_file">' . $_GET['qqfile'] . '</a></li>';
     $this->result = array('test' => $this->result['error']);
     $this->_response->setData($this->result);
     $this->_response->send();
 }
<!-- required div layout ends -->

<hr/>Logger:<br/><div id='logger'></div>

<?php 
// the widget
//
$this->widget('application.components.MyYiiFileManViewer', array('launch_selector' => '#file-picker', 'list_selector' => '#file-picker-viewer', 'uploader_selector' => '#myuploader', 'delete_confirm_message' => 'Confirm deletion ?', 'select_confirm_message' => 'Confirm selected items ?', 'no_selection_message' => 'You are required to select some file', 'onBeforeAction' => "function(viewer,action,file_ids) { return true; }", 'onAfterAction' => "function(viewer,action,file_ids, ok, response) {\n\t\t\t\tif(action == 'select'){\n\t\t\t\t  // actions: select | delete\n\t\t\t\t  \$.each(file_ids, function(i, item){\n\t\t\t\t  \$('#logger').append('file_id='+item.file_id\n\t\t\t\t  + ', <img src=\\''+item.url+'&size=full\\'><br/>');\n\t\t\t\t});\n\t\t\t}\n\t\t}", 'onClientSideUploaderError' => "function(messages){\n\t\t\t\t\$(messages).each(function(i,m){  alert(m); });\n\t\t\t}\n\t\t", 'onClientUploaderProgress' => "function(status, progress){\n\t\t\t\$('#logger').append(\n\t\t\t\t'progress: '+status+' '+progress+'%<br/>');\n\t\t\t}"));
if (User::model()->isAuthor()) {
    echo Yii::t('site', 'Notes to the author') . ': ' . $order->getAttribute('author_notes');
}
?>
<table>
    <tr>
        <?php 
foreach (ZakazParts::model()->attributeLabels() as $k => $v) {
    if (User::model()->isAuthor() || $k == 'file') {
        echo '<th>' . CHtml::encode($v) . '</th>';
    }
}
?>
    </tr>
    <?php 
$this->widget('zii.widgets.CListView', array('dataProvider' => $parts, 'itemView' => '_part'));
?>
</table>
<?php 
foreach ($messages as $message) {
    ?>
        <?php 
    echo $message->date;
echo $data['id'];
?>
" id="part_title_<?php 
echo $data['id'];
?>
">
                            <?php 
echo $data['title'];
?>
                        </a>
                    </h4>
                </div>
                <div class="title-time">
                    <?php 
$url = Yii::app()->createUrl('/project/zakazParts/apiEditPart');
$this->widget('ext.juidatetimepicker.EJuiDateTimePicker', array('model' => ZakazParts::model()->findByPk($data['id']), 'id' => 'partDate' . $data['id'], 'attribute' => 'dbdate', 'options' => array('onSelect' => "js:function(dateText,inst){\n                                jQuery.post('{$url}',JSON.stringify({dbdate:dateText,id:\$(this).attr('id').substr(8)}));\n                            }")));
?>
                </div>
            </div>
            <div id="collapseOne<?php 
echo $data['id'];
?>
" class="panel-collapse collapse">
                <div class="panel-body">

                    <p>
                        <input type="text" value="<?php 
echo $data['title'];
?>
" onkeyup="change_title(this.value,<?php 
echo $data['id'];
 public function manager()
 {
     // Дата информирования менеджера
     $projectsModel = Zakaz::model()->findAll('status<>:status', array(':status' => 5));
     foreach ($projectsModel as $project) {
         $dateStart = strtotime(date('Y-m-d H:i', time())) - self::INTERVAL * 60;
         //echo 'order #'.$project->id.' '.$project->title.': '.$project->manager_informed."\n";
         if (strtotime(date('Y-m-d H:i', strtotime($project->manager_informed))) >= $dateStart && strtotime(date('Y-m-d H:i', strtotime($project->manager_informed))) < strtotime(date('Y-m-d H:i', time()))) {
             //echo Company::getId().' #'.$project->id.' manager informed'."\n";
             Yii::import('application.modules.project.components.EventHelper');
             EventHelper::managerInformed($project->id);
         }
     }
     // У части заказа незавершенного заказа
     $projectsPartsModel = ZakazParts::model()->findAllByAttributes(array('status_id' => '1'));
     foreach ($projectsPartsModel as $projectStage) {
         $dateStart = strtotime(date('Y-m-d H:i', time())) - self::INTERVAL * 60;
         if (strtotime(date('Y-m-d H:i', strtotime($projectStage->date))) >= $dateStart && strtotime(date('Y-m-d H:i', strtotime($projectStage->date))) < strtotime(date('Y-m-d H:i', time()))) {
             Yii::import('application.modules.project.components.EventHelper');
             EventHelper::stageExpired($projectStage->proj_id);
         }
     }
 }
 public function actionStatus()
 {
     $row = array('status_id' => Yii::app()->request->getPost('status_id'));
     $id = Yii::app()->request->getPost('id');
     $condition = array();
     $params = array();
     ZakazParts::model()->updateByPk($id, $row, $condition, $params);
     Yii::app()->end();
 }
 public function getClosestDate()
 {
     $date = $this->author_informed;
     $parts = ZakazParts::model()->findAllByAttributes(array('proj_id' => $this->id));
     foreach ($parts as $part) {
         if ($part->date < $date) {
             $date = $part->date;
         }
     }
     return $date;
 }
 public function actionStatus()
 {
     $row = array('status_id' => Yii::app()->request->getPost('status_id'));
     $id = Yii::app()->request->getPost('id');
     $condition = array();
     $params = array();
     ZakazParts::model()->updateByPk($id, $row, $condition, $params);
     if ($row['status_id'] == 3) {
         $email = new Emails();
         $orderId = Yii::app()->request->getPost('id');
         $typeId = Emails::TYPE_14;
         $order = Zakaz::model()->findByPk($orderId);
         $user = User::model()->findByPk($order->user_id);
         $email->to_id = $user->id;
         $profile = Profile::model()->findAll("`user_id`='{$user->id}'");
         $rec = Templates::model()->findAll("`type_id`='{$typeId}'");
         $title = $rec[0]->title;
         $email->name = $profle->firstname;
         if (strlen($email->name) < 2) {
             $email->name = $user->username;
         }
         $email->login = $user->username;
         $email->num_order = $orderId;
         $email->page_order = 'http://' . $_SERVER['SERVER_NAME'] . '/project/chat?orderId=' . $orderId;
         $email->message = $rec[0]->text;
         echo '<br>$user->email=' . $user->email;
         $email->sendTo($user->email, $rec[0]->text, $typeId);
     }
     Yii::app()->end();
 }
 public function init()
 {
     $this->arrDataProvider = new CArrayDataProvider(ZakazParts::model()->with('files')->findAllByAttributes(['proj_id' => $this->projectId]), array('pagination' => array('pageSize' => 100)));
 }
 public function actionView($orderId)
 {
     $order = Zakaz::model()->resetScope()->findByPk($orderId);
     $parts = ZakazParts::model()->findAll(array('condition' => "`proj_id`='{$orderId}'"));
     $messageForAuthor = Templates::model()->getTemplate(Templates::TYPE_AUTHOR_RESPONSE_PROJECT);
     //$isGuest = Yii::app()->user->isGuest;
     $isGuest = Yii::app()->user->isGuest();
     if ($isGuest || User::model()->isManager()) {
         Yii::app()->theme = 'client';
         // если гость прошёл по ссылке на неcуществующий
         // проект, отправляем его на регистрацию
         $url = 'http://' . $_SERVER['SERVER_NAME'] . '/user/login';
         if (!$order) {
             $this->redirect($url);
         }
         /*$moderate_types = EventHelper::get_moderate_types_string();
         		$events = Events::model()->findAll(array(
         			'condition' => "`event_id`='$orderId' AND `type` in ($moderate_types)",
         			'order' => 'timestamp DESC'
         			),
         			array(':event_id'=> $orderId) 			
         		);
         		$moderated = count($events) == 0;
         		// если гость прошёл по ссылке на непромодерированный
         		// проект, отправляем его на регистрацию
         		if (!$moderated) $this->redirect( Yii::app()->createUrl('user/login'));
         		*/
     } elseif (Yii::app()->user->id == $order->executor) {
         // Current executor
         $this->redirect(Yii::app()->createUrl('/project/chat', array('orderId' => $orderId)));
     }
     if ($isGuest || User::model()->isAuthor()) {
         $buttonTemplates = Templates::model()->findAllByAttributes(array('type_id' => $isGuest ? 30 : 29));
     }
     $this->render('view', array('orderId' => $orderId, 'order' => $order, 'isGuest' => $isGuest, 'parts' => $parts, 'messageForAuthor' => $messageForAuthor, 'buttonTemplates' => $buttonTemplates));
     //Yii::app()->end();
 }
 public function actionStatus()
 {
     $status_id = Yii::app()->request->getPost('status_id');
     $id = Yii::app()->request->getPost('id');
     if (User::model()->isAuthor() && $status_id == '+1' && $id) {
         $stage = ZakazParts::model()->findByPk($id);
         if (User::model()->isExecutor($stage->proj_id) && $stage->status_id == 1) {
             $stage->status_id = 2;
             $stage->save();
             echo $stage->status->status;
             EventHelper::stageDoneByExecutor($stage->proj_id, $stage->title);
         } else {
             echo 'Wrong base status';
         }
     } elseif (User::model()->isCustomer() && $status_id == '+1' && $id) {
         $stage = ZakazParts::model()->findByPk($id);
         if (User::model()->isOwner($stage->proj_id) && $stage->status_id == 3) {
             $stage->status_id = 4;
             $stage->save();
             //echo $stage->status->status;
             echo ProjectModule::t('Approved by me');
             EventHelper::stageDoneByCustomer($stage->proj_id, $stage->title);
         } else {
             echo 'Wrong base status';
         }
     } elseif (User::model()->isManager() && $status_id && $id) {
         $orderId = Yii::app()->request->getPost('orderId');
         $row = array('status_id' => $status_id);
         $condition = array();
         $params = array();
         ZakazParts::model()->updateByPk($id, $row, $condition, $params);
         if ((int) $status_id == 3) {
             $parts = ZakazParts::model()->findAll("`proj_id` = '{$orderId}' AND `status_id` IN (0,1,2)");
             $order = Zakaz::model()->resetScope()->findByPk($orderId);
             $subject_order = $order->title;
             $user_id = $order->user_id;
             $user = User::model()->findByPk($user_id);
             $order->setCustomerEvents(2);
             $email = new Emails();
             if (count($parts) > 0) {
                 $type_id = Emails::TYPE_14;
             } else {
                 $type_id = Emails::TYPE_15;
             }
             $rec = Templates::model()->findAll("`type_id`='{$type_id}'");
             echo count($parts);
             $title = $rec[0]->title;
             $body = $rec[0]->text;
             $email->name = $user->full_name;
             if (strlen($email->name) < 2) {
                 $email->name = $user->username;
             }
             $email->num_order = $orderId;
             //		$model->date = date('Y-m-d H:i:s');
             $email->subject_order = $subject_order;
             $email->num_order = $orderId;
             $email->page_order = 'http://' . $_SERVER['SERVER_NAME'] . '/project/chat?orderId=' . $orderId;
             $email->sendTo($user->email, $rec[0]->title, $rec[0]->text, $type_id);
         }
     }
 }
 public function search()
 {
     // @todo Please modify the following code to remove attributes that should not be searched.
     $criteria = new CDbCriteria();
     $criteria->compare('t.id', $this->id);
     $criteria->with = array('parts' => array('select' => 'parts.date, parts.status_id', 'order' => 'parts.date'));
     $criteria->together = true;
     $criteria->compare('parts.status_id', $this->lastPartStatus, true);
     $criteria->compare('DATE_FORMAT(max_exec_date, "%d.%m.%Y")', substr($this->dbmax_exec_date, 0, 10), true);
     $criteria->compare('DATE_FORMAT(author_informed, "%d.%m.%Y")', substr($this->dbauthor_informed, 0, 10), true);
     $criteria->compare('DATE_FORMAT(manager_informed, "%d.%m.%Y")', substr($this->dbmanager_informed, 0, 10), true);
     $criteria->compare('DATE_FORMAT(parts.date, "%d.%m.%Y")', substr($this->lastPartDate, 0, 10), true);
     $fields = $this->getFields();
     foreach ($fields as $field) {
         $tmp = $field->varname;
         if (isset($this->{$tmp}) && $field->field_type == 'LIST' && $this->{$tmp} != '') {
             $criteria->compare('t.' . $tmp, explode(',', $this->{$tmp}));
         } elseif ($field->field_type == 'VARCHAR' || $field->field_type == 'TEXT') {
             $criteria->compare('t.' . $tmp, $this->{$tmp}, true);
         } else {
             $criteria->compare('t.' . $tmp, $this->{$tmp});
         }
     }
     if (!$this->status or $this->status == 0) {
         /// Так ли делать
         $criteria->addNotInCondition('status', array(5));
     } else {
         if ($this->status == -1) {
             // show all
         } else {
             $criteria->compare('status', $this->status);
         }
     }
     $sort = new CSort();
     $sort->defaultOrder = 't.id ASC';
     $sort->attributes = array('dateCreation' => array('asc' => 't.date', 'desc' => 't.date desc'), 'managerInformed' => array('asc' => 't.manager_informed', 'desc' => 't.manager_informed desc'), 'dateFinish' => array('asc' => 't.date_finish', 'desc' => 't.date_finish desc'), '*');
     $dataProvider = new CActiveDataProvider($this, array('criteria' => $criteria, 'sort' => $sort, 'pagination' => false));
     $data = $dataProvider->data;
     $keys = $dataProvider->keys;
     for ($i = 0; $i < count($data); $i++) {
         if ($data[$i]->parts[0]->date != ZakazParts::model()->getDateLastUncompleted($data[$i]->id)) {
             for ($j = $i; $j < count($data) - 1; $j++) {
                 $data[$j] = $data[$j + 1];
                 $keys[$j] = $keys[$j + 1];
             }
             unset($data[count($data) - 1]);
             unset($keys[count($keys) - 1]);
         }
     }
     $dataProvider->data = $data;
     $dataProvider->keys = $keys;
     return $dataProvider;
 }