Exemplo n.º 1
0
 public function ajaxSendCall()
 {
     try {
         $numberListTable = TableRegistry::get('NumberLists');
         $sendQueueTable = TableRegistry::get('SendQueues');
         $numberTable = TableRegistry::get('Numbers');
         // Check if list exists
         $numberList = $numberListTable->find('all', ['conditions' => ['number_list_id' => $this->request->data['call']['number_list_id']]]);
         if (!$numberList->count()) {
             throw new \Exception('Cannot locate list.');
         }
         $number = $numberTable->find('all', ['conditions' => ['number_list_id' => $this->request->data['call']['number_list_id']]]);
         $numberCount = $number->count();
         if (!$numberCount) {
             throw new \Exception('No numbers in the list');
         }
         $data = ['unique_id' => Text::uuid(), 'type' => 2, 'number_list_id' => $this->request->data['call']['number_list_id'], 'status' => 0, 'message' => $this->request->data['call']['message'], 'audio_id' => $this->request->data['call']['audio_id'], 'request_by' => null, 'total' => $numberCount, 'create_datetime' => new \DateTime('now', new \DateTimeZone('UTC'))];
         $sendQueue = $sendQueueTable->newEntity($data);
         $sendQueueTable->save($sendQueue);
         // Hit the cron
         shell_exec(ROOT . DS . 'bin' . DS . 'cake SendCall ' . $sendQueue->send_queue_id . ' > /dev/null 2>/dev/null &');
         $response['status'] = 1;
         $response['sendQueueId'] = $sendQueue->send_queue_id;
         $response['numberCount'] = $numberCount;
     } catch (\Exception $ex) {
         $response['status'] = 0;
         $response['message'] = $ex->getMessage();
     }
     $this->set(compact('response'));
     $this->set('_serialize', ['response']);
 }
Exemplo n.º 2
0
 public function add()
 {
     $clientInfo = $this->ClientInfos->newEntity();
     if ($this->request->is('post')) {
         $userid = Text::uuid();
         $contactid = Text::uuid();
         $clientid = Text::uuid();
         $this->loadModel('Users');
         $users = $this->Users->newEntity();
         $users = $this->Users->patchEntity($users, $this->request->data['Users']);
         $this->Users->save($users);
         $this->loadModel('ClientInfos');
         $clientInfos = $this->ClientInfos->newEntity();
         $clientInfos = $this->ClientInfos->patchEntity($clientInfos, $this->request->data['ClientInfos']);
         $this->ClientInfos->save($clientInfos);
         $this->loadModel('ClientContacts');
         $clientContacts = $this->ClientContacts->newEntity();
         $clientContacts = $this->ClientContacts->patchEntity($clientContacts, $this->request->data['ClientContacts']);
         $this->ClientContacts->save($clientContacts);
         return $this->redirect(['controller' => 'ClientDevices', 'action' => 'add']);
     }
     $clientTypes = $this->ClientInfos->ClientTypes->find('list', ['limit' => 200]);
     $companyTypes = $this->ClientInfos->CompanyTypes->find('list', ['limit' => 200]);
     $this->set(compact('clientInfo', 'clientTypes', 'companyTypes'));
     $this->set('_serialize', ['clientInfo']);
 }
Exemplo n.º 3
0
 private static function request_id()
 {
     if (empty(self::$_request_id)) {
         self::$_request_id = Text::uuid();
     }
     return self::$_request_id;
 }
Exemplo n.º 4
0
 public function send($data, $old_data = null)
 {
     if (!empty($data)) {
         $filename = $data['name'];
         $file_tmp_name = $data['tmp_name'];
         $dir_root = WWW_ROOT . 'img' . DS . 'uploads';
         $dir = 'uploads';
         $allowed = array('png', 'jpg', 'jpeg');
         if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
             return false;
         } elseif (is_uploaded_file($file_tmp_name)) {
             if ($old_data != null) {
                 $old_file = substr(strrchr($old_data, DS), 1);
                 if (file_exists($dir_root . DS . $old_file)) {
                     unlink($dir_root . DS . $old_file);
                 }
             }
             $file = Text::uuid() . '-' . $filename;
             // enregistrement du nom du fichier
             $file_root = $dir_root . DS . $file;
             // definition du chemin ou sera stocker le fichier
             move_uploaded_file($file_tmp_name, $file_root);
             // deplacement du fichier
             $filedb = $dir . DS . $file;
             // definition du chemin qui sera utilise dans la base de donnee
             return $filedb;
         }
     }
 }
Exemplo n.º 5
0
 /**
  * group link function
  * @param string $title title for menu link
  * @param array $urls force array
  * @param array $options configure for link
  * @return string inside <li> tag
  */
 public function groupLink($title, array $urls = [], array $options = [])
 {
     $result = '<li class="panel panel-default dropdown">';
     $controller = $this->Html->request->controller;
     foreach ($urls as $k => $v) {
         if (isset($v[1]) && $controller === $v[1]['controller']) {
             $result = '<li class="active panel panel-default dropdown">';
             break;
         }
     }
     $collapseId = Text::uuid();
     $result .= $this->Html->link($title, '#' . $collapseId, ['data-toggle' => 'collapse', 'escape' => false]);
     $result .= '<div id="' . $collapseId . '" class="panel-collapse collapse">';
     $result .= '<div class="panel-body">';
     $result .= '<ul class="nav navbar-nav">';
     foreach ($urls as $k => $v) {
         if (empty($v[0]) || empty($v[1])) {
             continue;
         }
         $result .= '<li>' . $this->Html->link($v[0], $v[1]) . '</li>';
     }
     $result .= '</ul>';
     $result .= '</div>';
     $result .= '</div>';
     $result .= '</li>';
     return $result;
 }
Exemplo n.º 6
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $municipios = $this->Locais->Municipios->find('all')->toArray();
     $array;
     $op;
     $i = 0;
     foreach ($municipios as $x) {
         $op[$i] = $x['cnm_municipio'] . ' (' . $x['ccd_municipio'] . ')';
         $array[$i] = $x['id'];
         $i++;
     }
     $local = $this->Locais->newEntity();
     if ($this->request->is('post')) {
         $local = $this->Locais->patchEntity($local, $this->request->data);
         $local->id = Text::uuid();
         $local->municipio_id = $array[$local->municipio_id];
         if ($this->Locais->save($local)) {
             $this->Flash->success(__('O local foi salvo.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('O local não pôde ser salvo. Tente novamente.'));
         }
     }
     $this->set(compact('local', 'op'));
     $this->set('_serialize', ['local']);
 }
Exemplo n.º 7
0
 /**
  * Render a text widget or other simple widget like email/tel/number.
  *
  * This method accepts a number of keys:
  *
  * - `name` The name attribute.
  * - `val` The value attribute.
  * - `escape` Set to false to disable escaping on all attributes.
  *
  * Any other keys provided in $data will be converted into HTML attributes.
  *
  * @param array $data The data to build an input with.
  * @param \Cake\View\Form\ContextInterface $context The current form context.
  * @return string
  */
 public function render(array $data, ContextInterface $context)
 {
     $data += ['name' => '', 'val' => null, 'type' => 'text', 'mode' => 'datetime', 'escape' => true, 'readonly' => true, 'templateVars' => []];
     // mode value and class
     $mode = $data['mode'];
     $hval = $data['value'] = $data['val'];
     $data['class'] = $data['type'];
     unset($data['val'], $data['mode']);
     // transform into frozen time if not already
     if (!($data['value'] instanceof FrozenTime || $data['value'] instanceof FrozenDate)) {
         $data['value'] = new FrozenTime($data['value']);
     }
     // transform values
     if ($mode == 'datetime') {
         $hval = $data['value']->format('Y-m-d H:i:s');
         $data['value'] = $data['value']->format('d-M-Y H:i:s');
     }
     if ($mode == 'date') {
         $hval = $data['value']->format('Y-m-d');
         $data['value'] = $data['value']->format('d-M-Y');
     }
     if ($mode == 'time') {
         $hval = $data['value'] = $data['value']->format('H:i:s');
     }
     // render
     $rand = Text::uuid();
     return "<div id='{$rand}' style='position: relative;'>" . $this->_templates->format('input', ['name' => $data['name'], 'type' => 'hidden', 'attrs' => $this->_templates->formatAttributes(['value' => $hval])]) . $this->_templates->format('input', ['name' => $data['name'] . '-' . $rand, 'type' => $mode, 'templateVars' => $data['templateVars'], 'attrs' => $this->_templates->formatAttributes($data, ['name', 'type'])]) . "<div id='dtpicker-{$rand}'></div><scriptend>\$(document).ready(Backend.DTPicker('{$rand}', '{$mode}'));</scriptend></div>";
 }
Exemplo n.º 8
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $boletos = $this->Boletoxretornos->Boletos->find('all')->toArray();
     $arrayBoletos;
     $opBoletos;
     $i = 0;
     foreach ($boletos as $x) {
         $arrayBoletos[$i] = $x->id;
         $opBoletos[$i] = $x->inr_boleto;
         $i++;
     }
     $boletoxretorno = $this->Boletoxretornos->newEntity();
     if ($this->request->is('post')) {
         $boletoxretorno = $this->Boletoxretornos->patchEntity($boletoxretorno, $this->request->data);
         $boletoxretorno->id = Text::uuid();
         $boletoxretorno->boleto_id = $arrayBoletos[$boletoxretorno->boleto_id];
         if ($this->Boletoxretornos->save($boletoxretorno)) {
             $this->Flash->success(__('O retorno foi salvo.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('O retorno não pôde ser salvo. Tente novamente.'));
         }
     }
     $this->set(compact('boletoxretorno', 'opBoletos'));
     $this->set('_serialize', ['boletoxretorno']);
 }
Exemplo n.º 9
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $participantes = $this->Boletos->Participantes->find('all')->toArray();
     $arrayParticipantes;
     $opParticipantes;
     $i = 0;
     foreach ($participantes as $x) {
         $opParticipantes[$i] = $x['cnm_participante'];
         $arrayParticipantes[$i] = $x['id'];
         $i++;
     }
     $boleto = $this->Boletos->newEntity();
     if ($this->request->is('post')) {
         $boleto = $this->Boletos->patchEntity($boleto, $this->request->data);
         $boleto->id = Text::uuid();
         $boleto->participante_id = $arrayParticipantes[$boleto->participante_id];
         if ($this->Boletos->save($boleto)) {
             $this->Flash->success(__('O boleto foi salvo.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('O boleto não pôde ser salvo. Tente novamente.'));
         }
     }
     $this->set(compact('boleto', 'opParticipantes'));
     $this->set('_serialize', ['boleto']);
 }
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add($idSub)
 {
     $submissoes = $this->Submissaoxcoautores->Submissoes->find('all')->toArray();
     $i = 0;
     $arraySubmissoes;
     $opSubmissoes;
     foreach ($submissoes as $x) {
         $arraySubmissoes[$i] = $x->id;
         $opSubmissoes[$i] = $x->ctl_submissao;
         $i++;
     }
     $submissaoxcoautore = $this->Submissaoxcoautores->newEntity();
     if ($this->request->is('post')) {
         $submissaoxcoautore = $this->Submissaoxcoautores->patchEntity($submissaoxcoautore, $this->request->data);
         $submissaoxcoautore->id = Text::uuid();
         $submissaoxcoautore->submissao_id = $idSub;
         //$arraySubmissoes[$submissaoxcoautore->submissao_id];
         if ($this->Submissaoxcoautores->save($submissaoxcoautore)) {
             $this->Flash->success(__('O coautor foi salvo.'));
             return $this->redirect(['controller' => 'Submissoes', 'action' => 'index']);
         } else {
             $this->Flash->error(__('O coautor não pôde ser salvo. Tente novamente.'));
         }
     }
     $this->set(compact('submissaoxcoautore', 'opSubmissoes'));
     $this->set('_serialize', ['submissaoxcoautore']);
 }
Exemplo n.º 11
0
 /**
  * Run Method.
  *
  * Write your database seeder using this method.
  *
  * More information on writing seeders is available here:
  * http://docs.phinx.org/en/latest/seeding.html
  *
  * @return void
  */
 public function run()
 {
     $time = date("Y-m-d H:i:s");
     $data = [['id' => Text::uuid(), 'email' => '*****@*****.**', 'username' => 'administrator', 'realname' => 'Administrator', 'password' => (new DefaultPasswordHasher())->hash('adminadmin'), 'created' => $time, 'modified' => $time, 'role' => 'admin', 'status' => '1', 'preferences' => json_encode(Cake\Core\Configure::read('cms.defaultUserPreferences'))]];
     $table = $this->table('users');
     $table->insert($data)->save();
 }
Exemplo n.º 12
0
 /**
  * @return string
  */
 public function getName()
 {
     if (empty($this->name)) {
         $this->name = Text::uuid();
     }
     return $this->name;
 }
Exemplo n.º 13
0
 public function upload()
 {
     try {
         $audioTable = TableRegistry::get('Audios');
         $dateTimeUtc = new \DateTimeZone('UTC');
         $now = new \DateTime('now', $dateTimeUtc);
         // Generate file name
         $serverDir = TMP . 'files' . DS;
         $serverFileName = Text::uuid() . '.wav';
         $uploadFullPath = $serverDir . $serverFileName;
         // Move file to temp location
         if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadFullPath)) {
             throw new \Exception('Cannot copy file to tmp location: ' . $uploadFullPath);
         }
         $uploadFullPath = $this->__convertToPhoneAudio($uploadFullPath);
         $data = ['file_name' => $_FILES['file']['name'], 'server_dir' => $serverDir, 'server_name' => $serverFileName, 'create_datetime' => $now];
         $audio = $audioTable->newEntity($data);
         $audioTable->save($audio);
         $response['status'] = 1;
         $response['audioId'] = $audio->audio_id;
     } catch (\Excaption $ex) {
         $response['status'] = 0;
         $response['message'] = $ex->getMessage();
     }
     $this->set(compact('response'));
     $this->set('_serialize', ['response']);
 }
Exemplo n.º 14
0
 public function beforeSave(Event $event)
 {
     $entity = $event->data['entity'];
     if ($entity->isNew()) {
         $entity->api_key = Security::hash(Text::uuid());
     }
     return true;
 }
Exemplo n.º 15
0
 /**
  * Conditionally adds the `_auditTransaction` and `_auditQueue` keys to $options. They are
  * used to track all changes done inside the same transaction.
  *
  * @param Cake\Event\Event The Model event that is enclosed inside a transaction
  * @param Cake\Datasource\EntityInterface $entity The entity that is to be saved
  * @param ArrayObject $options The options to be passed to the save or delete operation
  * @return void
  */
 public function injectTracking(Event $event, EntityInterface $entity, ArrayObject $options)
 {
     if (!isset($options['_auditTransaction'])) {
         $options['_auditTransaction'] = Text::uuid();
     }
     if (!isset($options['_auditQueue'])) {
         $options['_auditQueue'] = new SplObjectStorage();
     }
 }
Exemplo n.º 16
0
 function __construct(Api $api, array $assertions = [], $id = null)
 {
     $this->api = $api;
     $this->assertions = $assertions;
     $this->report = new Report();
     if (is_null($id)) {
         $id = Text::uuid();
     }
     $this->id = $id;
 }
Exemplo n.º 17
0
 /**
  * Test saving new records allows manual uuids
  *
  * @return void
  */
 public function testSaveNewSpecificId()
 {
     $id = Text::uuid();
     $entity = new Entity(['id' => $id, 'name' => 'shiny and new', 'published' => true]);
     $table = TableRegistry::get('uuiditems');
     $this->assertSame($entity, $table->save($entity));
     $row = $table->find('all')->where(['id' => $id])->first();
     $this->assertNotEmpty($row);
     $this->assertSame($id, strtolower($row->id));
     $this->assertSame($entity->name, $row->name);
 }
Exemplo n.º 18
0
 public function upload()
 {
     ini_set("auto_detect_line_endings", true);
     ini_set('memory_limit', '512M');
     set_time_limit(600);
     require_once ROOT . DS . 'vendor' . DS . 'parsecsv.lib.php';
     try {
         $numberListTable = TableRegistry::get('NumberLists');
         $numberTable = TableRegistry::get('Numbers');
         // Generate temp file name
         $uploadFullPath = TMP . DS . Text::uuid();
         // Move file to temp location
         if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadFullPath)) {
             throw new \Exception('Cannot copy file to tmp location');
         }
         $dateTimeUtc = new \DateTimeZone('UTC');
         $now = new \DateTime('now', $dateTimeUtc);
         // Create new list
         $newNumberListData = ['list_name' => $this->request->data['list_name'], 'list_description' => $this->request->data['list_description'], 'create_datetime' => $now, 'update_datetime' => $now];
         $numberList = $numberListTable->newEntity($newNumberListData);
         $numberListTable->save($numberList);
         // Get the data from the file
         $csv = new \parseCSV();
         $csv->heading = false;
         $csv->auto($uploadFullPath);
         if (count($csv->data) == 0) {
             throw new \Exception('File is empty');
         }
         $newNumberData = [];
         foreach ($csv->data as $row) {
             $responseM360 = $this->M360->optInTfn($row[1]);
             //                $response['d'][] = $responseM360;
             $newNumberData = ['number_list_id' => $numberList->number_list_id, 'country_code' => $row[0], 'phone_number' => $row[1], 'opt_in_tfn' => (bool) $responseM360['Message360']['OptIns']['OptIn']['Status'] === 'updated', 'add_datetime' => $now];
             $number = $numberTable->newEntity($newNumberData);
             $numberTable->save($number);
         }
         //            $numbers = $numberTable->newEntity($newNumberData);
         //
         //            $numberTable->connection()->transactional(function () use ($numberTable, $numbers) {
         //                foreach ($numbers as $number) {
         //                    $numberTable->save($number, ['atomic' => false]);
         //                }
         //            });
         unlink($uploadFullPath);
         $response['i'] = $newNumberData;
         $response['status'] = 1;
     } catch (\Excaption $ex) {
         $response['status'] = 0;
         $response['message'] = $ex->getMessage();
     }
     $this->set(compact('response'));
     $this->set('_serialize', ['response']);
 }
 /**
  * Upload Handler
  *
  * @param string $uuid Uploaded files are saved under this directory. It should be unique
  *                     per form session.
  * @return void
  */
 public function upload($uuid = null)
 {
     if ($uuid) {
         // strip everything but valid UUID chars
         $uuid = preg_replace('/[^a-z\\-0-9]/', '', $uuid);
     } else {
         $uuid = Text::uuid();
     }
     $options = ['upload_dir' => Configure::read('Attachments.tmpUploadsPath') . DS . $uuid . DS, 'accept_file_types' => Configure::read('Attachments.acceptedFileTypes')];
     $uploadHandler = new \UploadHandler($options);
     $this->autoRender = false;
 }
Exemplo n.º 20
0
 /**
  * Setup csrf token.
  *
  * @param array $data
  * @return array
  */
 protected function _setCsrfToken(array $data)
 {
     if ($this->_csrfToken === true) {
         if (!isset($this->_cookie['csrfToken'])) {
             $this->_cookie['csrfToken'] = Text::uuid();
         }
         if (!isset($data['_csrfToken'])) {
             $data['_csrfToken'] = $this->_cookie['csrfToken'];
         }
     }
     return $data;
 }
Exemplo n.º 21
0
 /**
  * testMultipleUuidGeneration method
  *
  * @return void
  */
 public function testMultipleUuidGeneration()
 {
     $check = [];
     $count = mt_rand(10, 1000);
     $pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\$/";
     for ($i = 0; $i < $count; $i++) {
         $result = Text::uuid();
         $match = (bool) preg_match($pattern, $result);
         $this->assertTrue($match);
         $this->assertFalse(in_array($result, $check));
         $check[] = $result;
     }
 }
Exemplo n.º 22
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $this->autoRender = false;
     if ($this->request->is('post')) {
         $data = (array) json_decode(file_get_contents("php://input"));
         $data['uuid'] = Text::uuid();
         $data['user_id'] = $this->userID;
         $resource = $this->Resources->newEntity($data);
         if ($this->Resources->save($resource)) {
             echo json_encode(1);
         } else {
             echo json_encode(0);
         }
     }
 }
Exemplo n.º 23
0
 public function add()
 {
     $user = $this->Users->newEntity();
     if ($this->request->is('post')) {
         $user = $this->Users->patchEntity($user, $this->request->data, ['associated' => ['UserRoles']]);
         $user->uuid = Text::uuid();
         if ($this->Users->save($user)) {
             $this->Flash->success(__("L'utilisateur a bien été créé."));
             return $this->redirect(['action' => 'index']);
         }
         $this->Flash->error(__("Impossible de créer l'utilisateur."));
     }
     $userRoles = $this->Users->UserRoles->find('list', ['keyField' => 'id', 'valueField' => 'display']);
     $this->set(compact('user', 'userRoles'));
 }
Exemplo n.º 24
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     if ($this->request->is('ajax')) {
         $this->autoRender = false;
         $error = [];
         if (!empty($this->request->data)) {
             $data = array_map(function ($value) {
                 return trim($value);
             }, $this->request->data);
             $userData = [];
             $userData['username'] = $data['mailUserRegister'];
             $userData['password'] = $data['passwordRegister'];
             $userData['confirm_password'] = $data['rePasswordRegister'];
             $userData['auth_key'] = Text::uuid();
             if (!$this->Recaptcha->verify()) {
                 $error[] = 'عبارت تصویر امنیتی نادرست وارد شده است.';
             }
             //TODO:: dar in marhale bayad unique boodan username barresi shavad .. darhale hazer kar nemikonad
             //TODO:: chon checkRules dar in marhale ettefaq nemiofte, balke dar save ettefaq miofte
             $user = $this->Users->newEntity($userData, ['checkRules' => true]);
             if (!empty($user->errors())) {
                 $error = Hash::merge($error, Hash::extract($user->errors(), '{s}.{s}'));
             }
             if (empty($error)) {
                 if (!empty($data['presenterRegister'])) {
                     $presenterUser = $this->Users->find()->select(['id', 'username'])->where(['username' => $data['presenterRegister']])->first();
                     if (!empty($presenterUser)) {
                         $userData['presenter_id'] = $presenterUser['id'];
                     }
                 }
                 $this->eventManager()->dispatch(new Event('Users.Users.add.beforeSave', $this, ['user' => &$user]));
                 if ($this->Users->save($user)) {
                     $this->Flash->success(__d('users', 'The user has been saved.'));
                     echo json_encode($this->success());
                     $this->eventManager()->dispatch(new Event('Users.Users.add.success', $this, ['user' => &$user]));
                     return;
                 } else {
                     $error = Hash::merge($error, Hash::extract($user->errors(), '{s}.{s}'));
                 }
             }
         } else {
             $error[] = 'فرمت داده های ورودی معتبر نیست.';
         }
         echo json_encode($this->error($error, 'ERROR'));
         return;
     }
     $this->redirect('/');
 }
Exemplo n.º 25
0
 public function send($file)
 {
     if (!empty($file)) {
         $filename = $file['name'];
         $file_tmp_name = $file['tmp_name'];
         $dir = WWW_ROOT . 'img' . DS . 'uploads';
         $allowed = array('png', 'jpg', 'jpeg');
         if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
             throw new InternalErrorException("Error Processing Request.", 1);
         } elseif (is_uploaded_file($file_tmp_name)) {
             $uuid_filename = DS . Text::uuid() . '-' . $filename;
             move_uploaded_file($file_tmp_name, $dir . $uuid_filename);
             return $uuid_filename;
         }
     }
 }
Exemplo n.º 26
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $termo = $this->Termos->newEntity();
     if ($this->request->is('post')) {
         $termo = $this->Termos->patchEntity($termo, $this->request->data);
         $termo->id = Text::uuid();
         if ($this->Termos->save($termo)) {
             $this->Flash->success(__('O termo foi salvo.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('O termo não pôde ser salvo. Tente novamente.'));
         }
     }
     $this->set(compact('termo'));
     $this->set('_serialize', ['termo']);
 }
Exemplo n.º 27
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $organizadora = $this->Organizadoras->newEntity();
     if ($this->request->is('post')) {
         $organizadora = $this->Organizadoras->patchEntity($organizadora, $this->request->data);
         $organizadora->id = Text::uuid();
         if ($this->Organizadoras->save($organizadora)) {
             $this->Flash->success(__('A organizadora foi salva'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('A organizadora não pôde ser salva. Tente novamente.'));
         }
     }
     $this->set(compact('organizadora'));
     $this->set('_serialize', ['organizadora']);
 }
Exemplo n.º 28
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $areatematica = $this->Areatematicas->newEntity();
     if ($this->request->is('post')) {
         $areatematica = $this->Areatematicas->patchEntity($areatematica, $this->request->data);
         $areatematica->id = Text::uuid();
         if ($this->Areatematicas->save($areatematica)) {
             $this->Flash->success(__('A área temática foi salva.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('A área temática não pôde ser salva. Tente novamente.'));
         }
     }
     $eventos = $this->Areatematicas->Eventos->find('list', ['limit' => 200]);
     $this->set(compact('areatematica', 'eventos'));
     $this->set('_serialize', ['areatematica']);
 }
 public function beforeSave($event, $entity)
 {
     if (is_null($entity->id)) {
         if (empty($entity->file['tmp_name'])) {
             return false;
         }
         $entity->guid = Text::uuid();
         $entity->timestamp = Time::now();
         $full_image_name = 'pictures/' . $entity->guid . '.png';
         if (!imagepng(imagecreatefromstring(file_get_contents($entity->file['tmp_name'])), $full_image_name)) {
             return false;
         }
         $thumbnail_name = 'pictures/' . $entity->guid . '_thumb.png';
         $this->scale($full_image_name, $thumbnail_name);
         return true;
     }
 }
Exemplo n.º 30
0
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $client = $this->Clients->newEntity();
     if ($this->request->is('post')) {
         $this->request->data['uuid'] = Text::uuid();
         $this->request->data['created_by'] = $this->userID;
         $client = $this->Clients->patchEntity($client, $this->request->data);
         if ($this->Clients->save($client)) {
             $this->Flash->success(__('The client has been saved successfully'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('The client could not be saved. Please, try again.'));
         }
     }
     $this->set(compact('client'));
     $this->set('_serialize', ['client']);
 }