Esempio n. 1
0
 public function deleteAction()
 {
     $this->_disableRender();
     if ($this->getRequest()->getParam('all')) {
         $json = new ZendT_Json_Result();
         try {
             if (!$this->getRequest()->getParam('confirmacao')) {
                 $form = new ZendT_Form();
                 $form->setAction(ZendT_Url::getUri());
                 $params = $this->getRequest()->getParams();
                 $params['confirmacao'] = '1';
                 foreach ($params as $key => $val) {
                     $element = new ZendT_Form_Element_Hidden($key);
                     $element->setValue($val);
                     $form->addElement($element);
                 }
                 $msg = "Deseja remover todas as notificações?";
                 throw new ZendT_Exception_Confirm($msg . $form->render());
             } else {
                 if (Auth_Session_User::getInstance()->authenticated()) {
                     $this->getMapper()->setIdUsuario(Zend_Auth::getInstance()->getStorage()->read()->getId())->delete();
                 }
                 $json->setResult(true);
             }
         } catch (Exception $ex) {
             $json->setException($ex);
         }
         echo $json->render();
     } else {
         parent::deleteAction();
     }
 }
Esempio n. 2
0
 public function changePasswordAction()
 {
     $this->_disableRender();
     $this->setLayout(ZendT_Controller_Action::LAYOUT_AJAX);
     $_result = new ZendT_Json_Result();
     $user = $this->getRequest()->getParam('user');
     $pass = $this->getRequest()->getParam('pass');
     $newPass = $this->getRequest()->getParam('new_pass');
     try {
         $message = $this->_mapper->changePassword($user, $pass, $newPass);
         $_result->setResult(array('message' => _i18n('Senha alterada com sucesso!')));
     } catch (Exception $ex) {
         $_result->setException($ex);
     }
     echo $_result->render();
 }
Esempio n. 3
0
 public function mirrorAction()
 {
     $this->_disableRender();
     $_json = new ZendT_Json_Result();
     try {
         $adapter = $this->getRequest()->getParam('adapter');
         $adapterMirror = $this->getRequest()->getParam('adapter_mirror');
         $table = $this->getRequest()->getParam('table');
         $where = $this->getRequest()->getParam('where');
         $_table = new Sync_Model_Table();
         $result = $_table->mirror($table, $adapter, $adapterMirror, $where);
         $_json->setResult('Sincronizado!');
     } catch (Exception $ex) {
         $_json->setException($ex);
     }
     echo $_json->render();
 }
Esempio n. 4
0
 public function retrieveAction()
 {
     //parent::retrieveAction();
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $row = $this->_retrieve();
         $this->_setConfig($row);
         if (!$row) {
             $row = array('found' => false);
         }
         $json->setResult($row);
     } catch (Exception $Ex) {
         $json->setException($Ex);
     }
     echo $json->render();
 }
Esempio n. 5
0
 public function cancelarAction()
 {
     $this->_disableRender(true, true);
     $idPedido = $this->getRequest()->getParam('id');
     $_json = new ZendT_Json_Result();
     $this->getModel()->getAdapter()->beginTransaction();
     try {
         if (!$idPedido) {
             throw new ZendT_Exception_Alert(_i18n('Necessário informar um pedido'));
         }
         $this->getMapper()->setId($idPedido)->retrieve()->cancelar();
         $this->getModel()->getAdapter()->commit();
         $_json->setResult(array('ok' => 1));
     } catch (Exception $ex) {
         $_json->setException($ex);
         $this->getModel()->getAdapter()->rollBack();
     }
     echo $_json->render();
 }
Esempio n. 6
0
 protected function _quote()
 {
     $this->_disableRender();
     $fields = $this->getRequest()->getParam('fields');
     $values = $this->getRequest()->getParam('values');
     $mapper = $this->getRequest()->getParam('mapper');
     /**
      * @var Automacao_DataView_RegraAltoValor_MapperView
      */
     $_mapper = new $mapper();
     $columns = $_mapper->getColumns()->toArray();
     $_json = new ZendT_Json_Result();
     try {
         $result = array();
         $result['values'] = array();
         foreach ($fields as $index => $field) {
             if (stripos($values[$index], 'SELECT') !== false) {
                 $result['values'][$index] = $values[$index];
             } else {
                 $data = explode(';', $values[$index]);
                 $parseValue = '';
                 $column = $columns[strtolower($field)];
                 foreach ($data as $value) {
                     $column['mapperName']->set($value);
                     $value = $column['mapperName']->getValueToDb();
                     $value = $_mapper->getAdapter()->quote($value);
                     $parseValue .= ',' . $value;
                 }
                 $result['values'][$index] = substr($parseValue, 1);
             }
         }
         $_json->setResult($result);
     } catch (Exception $ex) {
         $_json->setException($ex);
     }
     echo $_json->render();
 }
Esempio n. 7
0
 public function uploadImagemAction()
 {
     $file = $this->getRequest()->getParam('imagem');
     if (!$file) {
         $this->_defineLayout();
         #Zend_Layout::getMvcInstance()->setLayout('window');
         $form = new Cms_Form_Conteudo_UploadImagem();
         $form->loadElements();
         $this->view->form = $form->render();
     } else {
         $this->_disableRender();
         $json = new ZendT_Json_Result();
         try {
             $size = $this->getRequest()->getParam('tamanho');
             $_conteudo = new Cms_Model_Conteudo_Imagem();
             $_fileSystem = new Ged_Model_Arquivo_FileSystem();
             if (!$file['file']) {
                 throw new ZendT_Exception_Alert("Favor selecionar um arquivo!");
             }
             $files = array();
             $files['file'] = explode(',', $file['file']);
             $files['type'] = explode(',', $file['type']);
             $files['name'] = explode(',', $file['name']);
             $url = array();
             for ($i = 0; $i < count($files['file']); $i++) {
                 $file['file'] = $files['file'][$i];
                 $file['type'] = $files['type'][$i];
                 $file['name'] = $files['name'][$i];
                 $_conteudo->setImage($file, $size);
                 $id = $_conteudo->getImage()->getValueToDb();
                 $url[] = $_fileSystem->getDirectoryAdress($id);
             }
             $json->setResult(array('url' => $url));
         } catch (Exception $ex) {
             $json->setException($ex);
         }
         echo $json->render();
     }
 }
Esempio n. 8
0
 public function existsFieldAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $param = $this->getRequest()->getParams();
         if ($param['id']) {
             $count = $this->getMapper()->getCountPrivilege($param['id']);
         }
     } catch (Exception $Ex) {
         $json->setException($Ex);
     }
     $json->setResult(array("count" => $count));
     echo $json->render();
 }
Esempio n. 9
0
 public function pluploadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $targetDir = ZendT_Lib::getTmpDir() . '/files/' . DIRECTORY_SEPARATOR . "plupload";
         // Create target dir
         if (!file_exists($targetDir)) {
             @($result = mkdir($targetDir));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
             }
         }
         if (!file_exists($targetDir)) {
             @($result = mkdir($targetDir));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
             }
         }
         //$targetDir = 'uploads';
         $cleanupTargetDir = true;
         // Remove old files
         $maxFileAge = 1 * 3600;
         // Temp file age in seconds
         // 5 minutes execution time
         @set_time_limit(5 * 60);
         // Uncomment this one to fake upload time
         // usleep(5000);
         // Get parameters
         $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
         $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
         $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
         // Clean the fileName for security reasons
         $fileName = removeAccent(trim($fileName));
         $fileName = preg_replace('/[^\\w\\._]+/', '_', $fileName);
         $fileName = str_replace(' ', '_', $fileName);
         // Make sure the fileName is unique but only if chunking is disabled
         if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
             $ext = strrpos($fileName, '.');
             $fileName_a = substr($fileName, 0, $ext);
             $fileName_b = substr($fileName, $ext);
             $count = 1;
             while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) {
                 $count++;
             }
             $fileName = $fileName_a . '_' . $count . $fileName_b;
         }
         $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
         // Remove old temp files
         if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) {
             while (($file = readdir($dir)) !== false) {
                 $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
                 // Remove temp file if it is older than the max age and is not the current file
                 if (preg_match('/\\.part$/', $file) && filemtime($tmpfilePath) < time() - $maxFileAge && $tmpfilePath != "{$filePath}.part") {
                     @unlink($tmpfilePath);
                 }
             }
             closedir($dir);
         } else {
             throw new ZendT_Exception_Error('Failed to open temp directory.', 100);
         }
         // Look for the content type header
         if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
             $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
         }
         if (isset($_SERVER["CONTENT_TYPE"])) {
             $contentType = $_SERVER["CONTENT_TYPE"];
         }
         // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
         if (strpos($contentType, "multipart") !== false) {
             if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
                 // Open temp file
                 $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
                 if ($out) {
                     // Read binary input stream and append it to temp file
                     $in = fopen($_FILES['file']['tmp_name'], "rb");
                     if ($in) {
                         while ($buff = fread($in, 4096)) {
                             fwrite($out, $buff);
                         }
                     } else {
                         throw new ZendT_Exception_Error('Failed to open input stream.', 101);
                     }
                     fclose($in);
                     fclose($out);
                     @unlink($_FILES['file']['tmp_name']);
                 } else {
                     throw new ZendT_Exception_Error('Failed to open output stream.', 102);
                 }
             } else {
                 throw new ZendT_Exception_Error('Failed to move uploaded file.', 103);
             }
         } else {
             // Open temp file
             $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
             if ($out) {
                 // Read binary input stream and append it to temp file
                 $in = fopen("php://input", "rb");
                 if ($in) {
                     while ($buff = fread($in, 4096)) {
                         fwrite($out, $buff);
                     }
                 } else {
                     throw new ZendT_Exception_Error('Failed to open input stream.', 104);
                 }
                 fclose($in);
                 fclose($out);
             } else {
                 throw new ZendT_Exception_Error('Failed to open output stream.', 105);
             }
         }
         // Check if file has been uploaded
         if (!$chunks || $chunk == $chunks - 1) {
             // Strip the temp .part suffix off
             @($result = rename("{$filePath}.part", $filePath));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível renomear o arquivo.', 1002);
             }
         }
         if ($this->getRequest()->getParam('platform')) {
             $_file = new ZendT_File($fileName, file_get_contents($filePath), $_FILES['file']['type']);
             if (file_exists($filePath)) {
                 unlink($filePath);
             }
             $infoFile = $_file->toArrayJson();
             $infoFile['size'] = $_FILES['file']['size'];
             $infoFile['type'] = $_FILES['file']['type'];
             $json->setResult($infoFile);
         } else {
             $json->setResult(base64_encode($filePath));
         }
     } catch (Exception $Ex) {
         $json->setException($Ex);
     }
     echo $json->toRpc();
 }