Example #1
0
 function updateCounterCache($keys = array(), $created = false)
 {
     parent::updateCounterCache($keys);
     if (isset($this->data['Purchase'])) {
         $this->log('Purchase::updateCounterCache');
         $this->log(array_keys($this->data));
         $cat_id = $this->data['Purchase']['category_id'];
         $date = $this->data['Purchase']['date'];
         // UPDATE MONTH TOTALS
         $dts = strtotime($date);
         $month = date('Y-m-01', $dts);
         $dts = strtotime($month);
         $next_month = date('Y-m-01', strtotime('+1 month', $dts));
         $month_sum = $this->find('first', array('fields' => 'SUM(amount) as amount', 'conditions' => array("Purchase.date >= '{$month}'", "Purchase.date < '{$next_month}'", 'Purchase.category_id' => $cat_id)));
         $month_sum = Set::extract($month_sum, 'Purchase.amount');
         App::Import('Model', 'MonthTotal');
         $m = new MonthTotal();
         $data = array('MonthTotal' => array('id' => $month . '-' . $cat_id, 'date' => $month, 'category_id' => $cat_id, 'amount' => $month_sum));
         $m->save($data);
         // UPDATE YEAR TOTALS
         $year = date('Y', strtotime($date)) . '-01-01';
         $dts = strtotime($date);
         $year = date('Y-01-01', $dts);
         $dts = strtotime($year);
         $next_year = date('Y-01-01', strtotime('+1 year', $dts));
         $year_sum = $this->find('first', array('fields' => 'SUM(amount) as amount', 'conditions' => array("Purchase.date >= '{$year}'", "Purchase.date < '{$next_year}'", 'Purchase.category_id' => $cat_id)));
         $year_sum = Set::extract($year_sum, 'Purchase.amount');
         App::Import('Model', 'YearTotal');
         $m = new YearTotal();
         $data = array('YearTotal' => array('id' => $year . '-' . $cat_id, 'date' => $year, 'category_id' => $cat_id, 'amount' => $year_sum));
         $m->save($data);
     }
 }
Example #2
0
 /**
  * Called after activating the hook in ExtensionsHooksController::admin_toggle()
  *
  * @param object $controller Controller
  * @return void
  */
 function onActivate(&$controller)
 {
     // ACL: set ACOs with permissions
     $controller->Croogo->addAco('NodeSchema');
     // the controller
     $controller->Croogo->addAco('NodeSchema/admin_index');
     // admin methods
     $controller->Croogo->addAco('NodeSchema/admin_add');
     $controller->Croogo->addAco('NodeSchema/admin_edit');
     $controller->Croogo->addAco('NodeSchema/admin_delete');
     $controller->Croogo->addAco('NodeSchema/admin_add_schema_field');
     $controller->Croogo->addAco('NodeSchema/admin_import');
     $controller->Croogo->addAco('NodeSchema/admin_export');
     // Install the database tables we need
     App::Import('CakeSchema');
     $CakeSchema = new CakeSchema();
     $db =& ConnectionManager::getDataSource('default');
     // TODO: How do we change this for installs?
     // A list of schema files to import for this plugin to work
     $schema_files = array('node_schema_fields.php', 'node_schemas.php', 'node_schemas_types.php');
     foreach ($schema_files as $schema_file) {
         $class_name = Inflector::camelize(substr($schema_file, 0, -4)) . 'Schema';
         $table_name = substr($schema_file, 0, -4);
         // Only build the tables if they don't already exist
         if (!in_array($table_name, $db->_sources)) {
             include_once APP . 'plugins' . DS . 'node_schema' . DS . 'config' . DS . 'schema' . DS . $schema_file;
             // Can app import also work here?
             $ActivateSchema = new $class_name();
             $created = false;
             if (isset($ActivateSchema->tables[$table_name])) {
                 $db->execute($db->createSchema($ActivateSchema, $table_name));
             }
         }
     }
 }
 /**
  * This function use for product category Listing  in admin panel
  */
 function shophead_index()
 {
     $this->layout = 'admin_layout';
     $this->set('title', 'Product Items Management');
     App::Import("Model", "ProductCategory");
     $this->ProductCategory = new ProductCategory();
     $categories_list = $this->ProductCategory->find('list', array('conditions' => array('ProductCategory.is_deleted' => 0), 'fields' => array('ProductCategory.id', 'ProductCategory.name')));
     $this->set('categories_list', $categories_list);
     $Category_join = array('table' => 'product_sub_categories', 'alias' => 'ProductSubCategory', 'type' => 'inner', 'conditions' => array('ProductItem.product_sub_category_id =ProductSubCategory.id'));
     $conditions = array('ProductItem.is_deleted' => 0);
     if (!empty($this->request->data)) {
         if ($this->request->data['ProductItem']['product_sub_category_id'] != "") {
             $conditions['ProductItem.product_sub_category_id'] = $this->request->data['ProductItem']['product_sub_category_id'];
             $this->request->params['named']['ProductItem.product_sub_category_id'] = $this->request->data['ProductItem']['product_sub_category_id'];
         }
         if ($this->request->data['ProductItem']['product_category_id'] != "") {
             $conditions['ProductItem.product_category_id'] = $this->request->data['ProductItem']['product_category_id'];
             $this->request->params['named']['ProductItem.product_category_id'] = $this->request->data['ProductItem']['product_category_id'];
         }
     } else {
         if (isset($this->request->params['named']['ProductItem.product_category_id']) && $this->request->params['named']['ProductItem.product_category_id'] != "") {
             $conditions['ProductItem.product_category_id'] = $this->request->params['named']['ProductItem.product_category_id'];
             $this->request->data['ProductItem']['product_category_id'] = $this->request->params['named']['ProductItem.product_category_id'];
         }
         if (isset($this->request->params['named']['ProductItem.product_sub_category_id']) && $this->request->params['named']['ProductItem.product_sub_category_id'] != "") {
             $conditions['ProductItem.product_sub_category_id'] = $this->request->params['named']['ProductItem.product_sub_category_id'];
             $this->request->data['ProductItem']['product_sub_category_id'] = $this->request->params['named']['ProductItem.product_sub_category_id'];
         }
     }
     $this->paginate = array('recursive' => 0, 'limit' => LIMIT, 'fields' => array('ProductSubCategory.name as catname,ProductItem.id,ProductItem.name,ProductItem.sort_order,ProductItem.created,ProductItem.status,ProductItem.updated,ProductItem.product_sub_category_id'), 'conditions' => $conditions, 'order' => array('ProductItem.sort_order' => 'Asc'), 'joins' => array($Category_join));
     $result = $this->paginate('ProductItem');
     //pr($result);
     $this->set('result', $result);
 }
 public function health()
 {
     App::Import('ConnectionManager');
     $MPSearch = ConnectionManager::getDataSource('MPSearch');
     $elasticSearch = $MPSearch->API->cluster()->health();
     $this->set(array('elasticSearch' => $elasticSearch, '_serialize' => array('elasticSearch')));
 }
Example #5
0
 function beforeSave($options = array())
 {
     if ($this->data[$this->name]['type'] == 'IssueCustomField' && !empty($this->data['CustomField']['id'])) {
         $assoc_trackers = Set::extract('{n}.CustomFieldsTracker.tracker_id', $this->CustomFieldsTracker->find('all', array('conditions' => array('custom_field_id' => $this->data['CustomField']['id']))));
         $tracker_ids = empty($this->data[$this->name]['tracker_id']) ? array() : $this->data[$this->name]['tracker_id'];
         $this->__add_trackers = array_diff($tracker_ids, $assoc_trackers);
         $this->__del_trackers = array_diff($assoc_trackers, $tracker_ids);
     }
     unset($this->data[$this->name]['tracker_id']);
     App::Import('vendor', 'spyc');
     if (!empty($this->data[$this->name]['possible_values']) && $this->data[$this->name]['field_format'] == 'list') {
         if (empty($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1])) {
             unset($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1]);
         }
         $this->data[$this->name]['possible_values'] = Spyc::YAMLDump($this->data[$this->name]['possible_values'], true);
     } else {
         $this->data[$this->name]['possible_values'] = '--- []';
     }
     if (empty($this->data[$this->name]['min_length'])) {
         $this->data[$this->name]['min_length'] = 0;
     }
     if (empty($this->data[$this->name]['max_length'])) {
         $this->data[$this->name]['max_length'] = 0;
     }
     return true;
 }
Example #6
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->name]['type']) && $this->data[$this->name]['type'] == 'IssueCustomField' && !empty($this->data['CustomField']['id'])) {
         $this->bindModel(array('hasMany' => array('CustomFieldsTracker')), false);
         $assoc_trackers = Set::extract('{n}.CustomFieldsTracker.tracker_id', $this->CustomFieldsTracker->find('all', array('conditions' => array('custom_field_id' => $this->data['CustomField']['id']))));
         $tracker_ids = empty($this->data[$this->name]['tracker_id']) ? array() : $this->data[$this->name]['tracker_id'];
         $this->__add_trackers = array_diff($tracker_ids, $assoc_trackers ? $assoc_trackers : array());
         $this->__del_trackers = array_diff($assoc_trackers ? $assoc_trackers : array(), $tracker_ids);
     }
     unset($this->data[$this->name]['tracker_id']);
     App::Import('vendor', 'georgious-cakephp-yaml-migrations-and-fixtures/spyc/spyc');
     if (!empty($this->data[$this->name]['possible_values']) && $this->data[$this->name]['field_format'] == 'list') {
         if (empty($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1])) {
             unset($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1]);
         }
         $this->data[$this->name]['possible_values'] = Spyc::YAMLDump($this->data[$this->name]['possible_values'], true);
     } else {
         $this->data[$this->name]['possible_values'] = '--- []';
     }
     if (empty($this->data[$this->name]['min_length'])) {
         $this->data[$this->name]['min_length'] = 0;
     }
     if (empty($this->data[$this->name]['max_length'])) {
         $this->data[$this->name]['max_length'] = 0;
     }
     return true;
 }
Example #7
0
 public function checkBetaKeyUsed($key)
 {
     App::Import('Model', 'BetaKey');
     $this->BetaKey = new BetaKey();
     // find the key they've given
     return $this->BetaKey->find('first', array('conditions' => array('key' => $this->data['User']['beta_key'], 'email' => $this->data['User']['email'])));
 }
Example #8
0
 function beforeDelete($cascade)
 {
     // Remove the extended data to be tidy.
     // First get the type id
     App::Import('Model', 'Type');
     $Type = new Type();
     $Type->recursive = -1;
     $type_record = Set::extract('/Type/id', $Type->find('first', array('fields' => array('Type.id'), 'conditions' => array('Type.alias' => $this->model->data['Node']['type']))));
     $type_id = $type_record[0];
     // Cool, now find all node schemas
     App::Import('Model', 'NodeSchema.NodeSchema');
     $NodeSchema = new NodeSchema();
     $NodeSchema->actsAs = array('Containable');
     $schemas = $NodeSchema->find('all', array('fields' => array('NodeSchema.table_name'), 'contains' => array('Type' => array('conditions' => array('Type.id' => $type_id)))));
     // Now loop through and check for records on those tables to remove
     if (is_array($schemas) && count($schemas) > 0) {
         foreach ($schemas as $schema) {
             $table_name = $schema['NodeSchema']['table_name'];
             $model = new Model(false, $table_name);
             $model->primaryKey = 'node_id';
             // set the primary key to the node_id
             if ($model->delete($this->model->data['Node']['id'], false)) {
                 return true;
             } else {
                 // return false; // There was some sort of error deleting the associated data. Do we even need this? It doesn't redirect, it stops. Have to handle the error.
             }
         }
     }
     return true;
 }
Example #9
0
 function test()
 {
     App::Import('Shell', 'Shell');
     App::Import('Vendor', array('shells/sniffer_data'));
     $myShell = new SnifferDataShell(new Object());
     $myShell->initialize();
     // 	Select the method to call
     $Shell = $myShell->main($view = true, $debug = false);
 }
Example #10
0
 function load($settings)
 {
     if (empty($settings)) {
         return false;
     }
     App::Import('ConnectionManager');
     $ds = ConnectionManager::getDataSource($settings);
     $this->config = $ds->config;
 }
Example #11
0
 function pushHelpers()
 {
     foreach ($this->controller->actionHelpers as $helper) {
         $_helper = ucfirst($helper);
         App::Import('Helper', $_helper);
         $_helperClassName = $helper . 'Helper';
         $this->controller->{$helper} = new $_helperClassName();
     }
 }
 /**
  * Loads a gateway object with the passed options
  *
  * @param string $options 
  * @return void
  * @author Dean
  */
 function _load($options = array())
 {
     App::Import('Vendor', 'AktiveMerchant', array('file' => 'aktive_merchant' . DS . 'lib' . DS . 'merchant.php'));
     if (isset($this->config['testing']) && $this->config['testing']) {
         Merchant_Billing_Base::mode('test');
     }
     $gatewayClass = 'Merchant_Billing_' . $this->config['gateway'];
     $this->gateway = new $gatewayClass($this->config);
 }
 public function admin_export($id = null)
 {
     if (!$id) {
         $this->notice('invalid');
     }
     $this->Template->recursive = -1;
     $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id);
     if (empty($template)) {
         $this->notice('invalid');
     }
     $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i";
     preg_match_all($pattern, $template['Template']['header'], $images);
     $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name'];
     $Folder = new Folder($path, 0777);
     $slash = $Folder->correctSlashFor($path);
     App::import('File');
     App::import('Folder');
     $File = new File($path . DS . 'template.xml', true, 0777);
     $imageFiles = array();
     if (!empty($images[1])) {
         foreach ($images[1] as $img) {
             $img = str_replace('/', $slash, $img);
             $img = str_replace('\\', $slash . $slash, $img);
             $imageFiles[] = $img;
             if (is_file(APP . 'webroot' . $img)) {
                 $Folder->create(dirname($path . $img), 0777);
                 $File->path = APP . 'webroot' . $img;
                 $File->copy(dirname($path . $img) . DS . basename($img));
             }
         }
     }
     $xml['template']['name'] = 'Infinitas Newsletter Template';
     $xml['template']['generator'] = 'Infinitas Template Generator';
     $xml['template']['version'] = $this->version;
     $xml['template']['template'] = $template['Template']['name'];
     $xml['template']['description'] = $template['Template']['description'];
     $xml['template']['author'] = $template['Template']['author'];
     $xml['data']['header'] = $template['Template']['header'];
     $xml['data']['footer'] = $template['Template']['footer'];
     $xml['files']['images'] = $imageFiles;
     App::Import('Helper', 'Xml');
     $Xml = new XmlHelper();
     $File->path = $path . DS . 'template.xml';
     $File->write($Xml->serialize($xml));
     App::import('Vendor', 'Zip', array('file' => 'zip.php'));
     $Zip = new CreateZipFile();
     $Zip->zipDirectory($path, null);
     $File = new File($path . DS . 'template.zip', true, 0777);
     $File->write($Zip->getZippedfile());
     $this->view = 'Media';
     $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS);
     $this->set($params);
     $Folder = new Folder($path);
     $Folder->read();
     $Folder->delete($path);
 }
 /**
  *显示页.
  */
 public function view($code)
 {
     App::Import('Vendor', 'barcode', array('file' => 'barcode.class.php'));
     $b = new BarCode();
     $this->layout = 'blank';
     $encoding = '128';
     $scale = '2';
     $mode = 'png';
     $b->barcode_print($code, $encoding, $scale, $mode);
 }
Example #15
0
 function beforeFilter()
 {
     App::Import('ConnectionManager');
     App::Import('DataSource');
     App::import(array('type' => 'File', 'name' => 'Twitter.TWITTER_CONFIG', 'file' => 'config' . DS . 'core.php'));
     App::import(array('type' => 'File', 'name' => 'Twitter.TwitterSource', 'file' => 'models' . DS . 'datasources' . DS . 'twitter_source.php'));
     $TwitterConfig =& new TWITTER_CONFIG();
     ConnectionManager::create('twitter', $TwitterConfig->login);
     $this->Twitter = ConnectionManager::getDataSource('twitter');
 }
Example #16
0
 /**
  * Creates the PHPMailer object and sets default values.
  * Must be called before working with the component!
  *
  * @access public
  * @return void
  */
 function startup(&$controller)
 {
     // Include the class file and create PHPMailer instance
     App::Import('Vendor', 'phpmailer', array('file' => 'phpmailer/class.phpmailer.php'));
     $this->m = new PHPMailer();
     // Set default PHPMailer variables (see PHPMailer API for more info)
     $this->From = 'noreply@ebocash.ebotunes.com';
     $this->FromName = 'eboCash';
     // set more PHPMailer vars, for smtp etc.
 }
Example #17
0
 function emoticons($text)
 {
     App::Import('Model', 'emoticon');
     $this->Emoticon = new Emoticon();
     $emoticons = $this->Emoticon->find('all', array('order' => 'code DESC', 'cache' => 'emoticons'));
     foreach ($emoticons as $emoticon) {
         // arrays are used in str_ireplace for speed, even though it's a single search
         $text = str_ireplace(array($emoticon['Emoticon']['code']), array($this->HtmlImage->image('icons/' . $emoticon['Emoticon']['name'], array('static' => true))), $text);
     }
     return $text;
 }
Example #18
0
 public function beforeSave(&$model)
 {
     App::Import('Lib', 'ImageUpload.Upload');
     foreach ($this->_fields[$model->alias] as $field => $configs) {
         if (!empty($model->data[$model->alias][$field]['name'])) {
             $handle = new Upload($model->data[$model->alias][$field]);
             $filename = $this->name($model, $field);
             $handle->file_new_name_body = $filename;
             $handle->image_resize = $this->settings[$model->alias]['image_resize'];
             $handle->image_ratio = $this->settings[$model->alias]['image_ratio'];
             $handle->image_ratio_crop = $this->settings[$model->alias]['image_ratio_crop'];
             $image_width = $this->settings[$model->alias][$field][0];
             $image_height = $this->settings[$model->alias][$field][1];
             $handle->image_x = $this->checkIntParam($image_width);
             $handle->image_y = $this->checkInTParam($image_height);
             $this->settings[$model->alias]['path_to_dir'];
             $handle->process($this->settings[$model->alias]['path_to_dir']);
             if ($handle->processed) {
                 $model->data[$model->alias][$field] = $filename . '.' . $handle->file_dst_name_ext;
             } else {
                 throw new NotFoundException('File could not be uploaded: ' . $handle->error);
             }
             if (!isset($model->data[$model->alias]['created'])) {
                 $this->delete($model, $field);
             }
             $params_number = count($this->settings[$model->alias][$field]);
             $thumbs = (int) ($params_number - 2) / 2;
             $n = 0;
             for ($i = 0; $i < $thumbs; $i++) {
                 $filename_thumb = 'thb' . $i . '_' . $filename;
                 $handle->file_new_name_body = $filename_thumb;
                 $handle->image_resize = $this->settings[$model->alias]['image_resize'];
                 $handle->image_ratio = $this->settings[$model->alias]['image_ratio'];
                 $handle->image_ratio_crop = $this->settings[$model->alias]['image_ratio_crop'];
                 $thumb_width = $this->settings[$model->alias][$field][2 + $n];
                 $thumb_height = $this->settings[$model->alias][$field][3 + $n];
                 $handle->image_x = $this->checkIntParam($thumb_width);
                 $handle->image_y = $this->checkInTParam($thumb_height);
                 $handle->process($this->settings[$model->alias]['path_to_dir']);
                 $upThumbImg = $handle->processed;
                 if (!$handle->processed) {
                     echo $handle->error;
                     return false;
                 }
                 $n += 2;
             }
             $handle->Clean();
         } else {
             unset($model->data[$model->alias][$field]);
         }
     }
     return true;
 }
Example #19
0
 function findDisciplinasByPrecendencia($plano, $ano = 1, $semestre = 1)
 {
     $disciplinas_id = $this->find('list', array('conditions' => array('Planoestudoano.ano <' => $ano), 'fields' => array('Planoestudoano.disciplina_id')));
     App::Import('Model', 'Disciplina');
     $disciplina = new Disciplina();
     $disciplinas = array();
     foreach ($disciplinas_id as $did) {
         $disciplina = $disciplina->findById($did);
         $nome_disciplina = $disciplina["Disciplina"]["name"];
         $disciplinas[$did] = $nome_disciplina;
     }
     return $disciplinas;
 }
Example #20
0
 /**
  * Requires MySQL
  *
  * @param compress file will be compressed with gzip
  * @param email If an email address is supplied, the file will be emailed and then deleted, otherwise it will remin on the filesystem
  *
  * @return false if the backup failed, true otherwise
  */
 function backup($compress = true, $email = null)
 {
     ini_set("memory_limit", "128M");
     // Perform backup
     $filename = TMP . date('Ymd-Hi') . ".sql";
     App::Import('ConnectionManager');
     $ds = ConnectionManager::getDataSource('default');
     $dsc = $ds->config;
     $command = "mysqldump -u {$dsc['login']} --password={$dsc['password']} {$dsc['database']} > {$filename}";
     $this->log($command);
     $result = exec($command, $output, $return_code);
     if ($return_code != 0) {
         $this->log('exec command failed for : ' . $command);
         $this->log($return_code);
         return false;
     } else {
         if ($compress) {
             exec("gzip {$filename}");
             $filename .= ".gz";
         }
         // Send backup
         if (!is_null($email)) {
             $date = date('d/m/Y');
             $filesize = number_format(filesize($filename) / 1048576, 0);
             $m = $this->Mailer;
             /*
             		$m->IsSMTP(true);
             		$m->SMTPAuth = true;
             		$m->Username = 'username@gmail.com';
             		$m->Password = 'password';
             		$m->Host = 'ssl://smtp.gmail.com:465';
             */
             $m->FromName = 'eboCash Backup Mailer';
             $m->AddAddress($email);
             $m->AddAttachment($filename);
             $m->Subject = "Database Backup - {$date}";
             $m->Body = "The Database Backup for {$date} is attached, the filesize is: {$filesize}MB.";
             if ($m->Send()) {
                 $this->log("Success");
                 unlink($filename);
                 return true;
             } else {
                 $this->log("Error, could not send: {$m->ErrorInfo}");
                 return false;
             }
         } else {
             return true;
         }
     }
 }
 public function getMap($alias, $page)
 {
     $size = 10000;
     $from = ($page - 1) * $size;
     App::Import('ConnectionManager');
     $MPSearch = ConnectionManager::getDataSource('MPSearch');
     $response = $MPSearch->search(array("size" => $size, "from" => $from, "query" => array("filtered" => array("filter" => array("and" => array("filters" => array(array("term" => array("_type" => "objects")), array("term" => array("dataset" => $alias))))))), "aggs" => array("all_weights" => array("global" => new \stdClass(), "aggs" => array("max_weight" => array("max" => array("field" => "weights.main.score"))))), "sort" => array(array('date' => 'desc'), array('title.raw' => 'asc')), "fields" => array('slug', 'id', 'weights.main.score')));
     $divider = isset($response['aggregations']['all_weights']['max_weight']['value']) && $response['aggregations']['all_weights']['max_weight']['value'] ? $response['aggregations']['all_weights']['max_weight']['value'] : 1;
     $map = array();
     foreach ($response['hits']['hits'] as $hit) {
         $map[] = array('id' => $hit['fields']['id'][0], 'slug' => $hit['fields']['slug'][0], 'weight' => $hit['fields']['weights.main.score'][0] / $divider);
     }
     return $map;
 }
Example #22
0
 public function getAllNotifications($uid)
 {
     $this->recursive = -1;
     $note = $this->find('all', array('conditions' => array('user_id' => $uid), 'order' => array('Notification.new', 'Notification.id')));
     // FIXME
     // This is hard coded to always return 'user', not necessarilly the best
     foreach ($note as $key => $val) {
         $type = Inflector::classify($val['Notification']['type']);
         App::Import('Model', $type);
         $this->{$type} = new $type();
         $data = $this->{$type}->find('first', array('conditions' => array($type . '.id' => $val['Notification']['model_id']), 'contain' => array('User')));
         $note[$key]['User'] = $data['User'];
     }
     return $note;
 }
Example #23
0
 /**
  * Some JodelJodel bindings
  * 
  * @access public
  */
 function beforeFilter()
 {
     parent::beforeFilter();
     App::Import('Behavior', 'Status.Status');
     //starts all status with nothing active
     StatusBehavior::setGlobalActiveStatuses(array('publishing_status' => array('active' => array(), 'overwrite' => true, 'mergeWithCurrentActiveStatuses' => false)));
     // in the applicationAppController or in each controller of a plugin (in beforeRender) is need to add the status, like this
     /*
     	StatusBehavior::setGlobalActiveStatuses(array(
     		'publishing_status' => array('active' => array('published'), 'overwrite' => true, 'mergeWithCurrentActiveStatuses' => false),
     	));
     */
     $curModule = array();
     if ($this->params['plugin']) {
         $curModule = Configure::read('jj.modules.' . $this->params['plugin']);
         if (empty($curModule)) {
             $module = split('_', $this->params['plugin']);
             if (isset($module[1])) {
                 $curModule = Configure::read('jj.modules.' . $module[1]);
             }
             if (empty($curModule)) {
                 if (isset($module[1])) {
                     $curModule = Configure::read('jj.modules.' . Inflector::singularize($module[1]));
                 }
             }
         }
     }
     if (!empty($curModule)) {
         list($plugin, $model) = pluginSplit($curModule['model']);
         if (!isset($curModule['viewUrl'])) {
             $curModule['viewUrl'] = array();
         }
         if (!is_array($curModule['viewUrl'])) {
             trigger_error('BackstageTypeBricklayerHelper::moduleView() - `viewUrl` configuration must be an array.');
             return false;
         }
         $plugin = Inflector::underscore($plugin);
         $standardUrl = $curModule['viewUrl'] + array('plugin' => $plugin, 'controller' => Inflector::pluralize($plugin), 'action' => 'view');
     } else {
         $standardUrl = array('controller' => 'controller', 'action' => 'view');
     }
     if ($this->params['action'] == $standardUrl['action'] && $this->params['controller'] == $standardUrl['controller']) {
         if ($this->JjAuth->can('view_drafts')) {
             //if the user have the permission view_drafts then the status are changed to published and draft
             StatusBehavior::setGlobalActiveStatuses(array('publishing_status' => array('active' => array('published', 'draft'), 'overwrite' => true, 'mergeWithCurrentActiveStatuses' => true)));
         }
     }
 }
Example #24
0
 public function search()
 {
     $this->autoRender = false;
     App::Import('ConnectionManager');
     $ds = ConnectionManager::getDataSource('default');
     $dsc = $ds->config;
     // get the search term from URL
     $mysqli = new mysqli($dsc['host'], $dsc['login'], $dsc['password'], $dsc['database']);
     $res = $mysqli->query("SELECT id,username as text FROM users");
     $result;
     foreach ($res->fetch_all() as $key => $tem) {
         $result[$key]['id'] = $tem[0];
         $result[$key]['text'] = $tem[1];
     }
     echo json_encode($result);
 }
 /**
  * Check between Model->data[modelname][custom_field_values][] and Database values
  */
 function beforeValidate(&$Model)
 {
     if (empty($this->available_custom_fields[$Model->alias])) {
         return true;
     }
     $fields = $this->available_custom_fields[$Model->alias];
     foreach ($fields as $field) {
         if (!empty($Model->data[$Model->alias]['custom_field_values']) && array_key_exists($field['CustomField']['id'], $Model->data[$Model->alias]['custom_field_values'])) {
             $data = $Model->data[$Model->alias]['custom_field_values'][$field['CustomField']['id']];
         } else {
             $data = '';
         }
         $message = '';
         $regex = false;
         if ($field['CustomField']['is_required']) {
             $regex = '/[^\\s]+/m';
             $message = 'validates_presence_of';
         }
         if (!$this->_check($regex, $data)) {
             $Model->validationErrors[$field['CustomField']['name']] = $message;
         } elseif (!empty($field['CustomField']['regexp'])) {
             $regex = '/' . $field['CustomField']['regexp'] . '/um';
             $message = 'validates_invalid_of';
             if (!$this->_check($regex, $data)) {
                 $Model->validationErrors[$field['CustomField']['name']] = $message;
             }
         }
         if ($field['CustomField']['field_format'] == 'list' && !empty($field['CustomField']['possible_values']) && !empty($data)) {
             App::Import('vendor', 'georgious-cakephp-yaml-migrations-and-fixtures/spyc/spyc');
             $list = Spyc::YAMLLoad($field['CustomField']['possible_values']);
             $options = array();
             if (!empty($list)) {
                 foreach ($list as $item) {
                     if (is_array($item)) {
                         $item = $item[0];
                     }
                     $options[$item] = $item;
                 }
             }
             if (!in_array($data, $options)) {
                 $Model->validationErrors[$field['CustomField']['name']] = $message;
             }
         }
     }
     // continue main model validates...
     return true;
 }
Example #26
0
 function getAllPrecedenciasByDisciplina($disciplina_id, $plano_id = null)
 {
     App::Import('Model', 'Grupodisciplina');
     $grupodisciplinas = new Grupodisciplina();
     $o = $grupodisciplinas->find('all', array('conditions' => array('planoestudo_id' => $plano_id, 'disciplina_id' => $disciplina_id, 'tipoprecedencia_id' => 'O'), 'fields' => array('Grupodisciplina.id', 'Disciplina.name')));
     $obr = array();
     foreach ($o as $ob) {
         $obr[$ob['Grupodisciplina']['id']] = $ob['Disciplina']['name'];
     }
     $a = $grupodisciplinas->find('all', array('conditions' => array('planoestudo_id' => $plano_id, 'disciplina_id' => $disciplina_id, 'tipoprecedencia_id' => 'A'), 'fields' => array('Grupodisciplina.id', 'Disciplina.name')));
     $acs = array();
     foreach ($a as $ac) {
         $acs[$ac['Grupodisciplina']['id']] = $ac['Disciplina']['name'];
     }
     $precedencias = array('a' => $acs, 'o' => $obr);
     return $precedencias;
 }
Example #27
0
 function add()
 {
     App::Import('Model', 'Logmv');
     $logmv = new Logmv();
     if (!empty($this->data)) {
         $this->Disciplina->create();
         if ($this->Disciplina->save($this->data)) {
             ////$logmv->logInsert(4,$this->Session->read('Auth.User.id'),$this->Disciplina->getLastInsertID(),$this->data["Disciplina"]["name"]);
             $this->Session->setFlash('** Dados Cadastrados com Sucesso **', 'flashok');
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash('Erro ao gravar dados. Por favor tente de novo.', 'flasherror');
         }
     }
     $grupodisciplinars = $this->Disciplina->Grupodisciplinar->find('list');
     $this->set(compact('grupodisciplinars'));
 }
 public function index()
 {
     $this->loadModel('Oauth');
     // read all the oauth consumers and add them to the array of available connections
     $read = $write = array();
     // base dir for consumer files
     $consumerDir = ROOT . DS . APP_DIR . DS . 'controllers' . DS . 'components' . DS . 'oauth_consumers';
     // open the dir
     if ($handle = opendir($consumerDir)) {
         // import the abstract consumer, it's needed by the other consumer files
         App::Import('File', 'abstractConsumer', array('file' => $consumerDir . DS . 'abstract_consumer.php'));
         // loop over every file in the dir
         while (false !== ($file = readdir($handle))) {
             // make sure it's what we want
             if ($file != "." && $file != ".." && $file != 'abstract_consumer.php') {
                 // grab the name of the service it's for
                 $consumerName = explode('_consumer', $file);
                 $consumerName = ucfirst($consumerName[0]);
                 // generate the class name for the consumer
                 $name = Inflector::classify(str_replace('.php', '', $file));
                 // import the consumer file
                 App::Import('File', $name, array('file' => $consumerDir . DS . $file));
                 // make it
                 $consumer = new $name();
                 // check if this consumer has expired, if it has it will be removed and have to be reconnected
                 $this->Oauth->checkExpires($this->currentUser['User']['id'], $consumerName);
                 // check if we're using post, if yes, we're writing
                 if (method_exists($consumer, 'post')) {
                     $write[] = array('Oauth' => array('name' => $consumerName, 'expires' => $consumer->expires));
                 }
                 // check if we're using get, if yes, we're reading
                 if (method_exists($consumer, 'get')) {
                     $read[] = array('Oauth' => array('name' => $consumerName, 'expires' => $consumer->expires));
                 }
                 unset($consumer);
             }
         }
         closedir($handle);
     }
     $connectedServices = array();
     foreach ($this->currentUser['Oauth'] as $service) {
         $connectedServices[] = $service['service'];
     }
     $this->set(compact('connectedServices', 'read', 'write'));
 }
Example #29
0
 function load($settings)
 {
     if (empty($settings) || !empty($this->settings)) {
         return false;
     }
     App::Import('ConnectionManager');
     $ds = ConnectionManager::getDataSource($settings);
     $this->config = $ds->config;
     $config = explode('.', $this->config['driver']);
     $config[1] = Inflector::underscore($config[1]);
     Configure::load(implode('.', $config));
     $this->settings = Configure::read($this->config['driver']);
     $this->fieldMap = $this->settings['fieldmap'];
     if (!empty($this->config['testing']) && $this->config['testing']) {
         $this->settings = array_merge($this->settings['defaults'], $this->settings['testing']);
     } else {
         $this->settings = $this->settings['defaults'];
     }
 }
Example #30
0
 function getPrivateId()
 {
     Configure::load('gitrbug');
     $id_n = Configure::read('gitrbug.num_secrets');
     Configure::load('gitrbug_secrets');
     $id_s = Configure::read('gitrbug_s.secrets');
     $id_a = unserialize(stripslashes($id_s));
     if (count($id_a) < $id_n) {
         App::Import('Model', 'Peer');
         $peerModel =& ClassRegistry::init('Peer');
         while (count($id_a) < $id_n) {
             $id_a[] = $peerModel->_genUUID();
         }
         Configure::write('gitrbug_s.secrets', serialize($id_a));
         Configure::store('gitrbug', 'gitrbug_secrets', Configure::read('gitrbug_s'));
     }
     $id_x = rand(0, $id_n - 1);
     return $id_a[$id_x];
 }