public function actionApiEditPart()
 {
     $folder = $this->folder();
     $this->_prepairJson();
     $partId = $this->_request->getParam('id');
     $model = ZakazParts::model()->findByPk($partId);
     foreach ($this->_request->_params as $par => $val) {
         $model->{$par} = $val;
     }
     if ($this->_request->isParam('files')) {
         $files = $this->_request->getParam('files');
         $path = $folder . $partId . '/';
         $this->checkDir($path);
         foreach ($files as $file) {
             $list = explode('.', $file);
             $newName = $this->getGuid();
             $filePath = $_SERVER['DOCUMENT_ROOT'] . $folder . 'temp/' . $file;
             $fileNewPath = $_SERVER['DOCUMENT_ROOT'] . $folder . $partId . '/' . $newName . "." . $list['1'];
             $probe = rename($filePath, $fileNewPath);
             $fileModel = new ZakazPartsFiles();
             $fileModel->part_id = $model->id;
             $fileModel->orig_name = $file;
             $fileModel->file_name = $newName . "." . $list['1'];
             $fileModel->comment = '';
             $fileModel->save();
         }
     }
     $this->_response->setData(array('result' => $model->save()));
     $this->_response->send();
 }
 public function actionUpload()
 {
     $this->_prepairJson();
     $folder = $_SERVER['DOCUMENT_ROOT'] . $this->folder() . $_GET['id'] . '/';
     $fileModel = new ZakazPartsFiles();
     $fileModel->part_id = $_GET['id'];
     $fileModel->orig_name = $_GET['qqfile'];
     $this->result = Tools::uploadMaterials($folder, false);
     if ($this->result['success']) {
         $fileModel->file_name = $this->result['fileName'];
         $part = ZakazParts::model()->findByPk($_GET['id']);
         if (User::model()->isManager()) {
             $fileModel->approved = 1;
         } else {
             EventHelper::newFileInStage($_GET['proj_id'], $part->title);
         }
         $fileModel->save();
     }
     //$this->result['html']='=)';//'<li>!!!<a href="' . $this->result['file_name'] . '" id="parts_file">' . $_GET['qqfile'] . '</a></li>';
     //$this->result = array('error' => $this->result['error']);
     $this->_response->setData($this->result);
     $this->_response->send();
 }