Ejemplo n.º 1
0
 public function setAddEncuesta()
 {
     global $uid;
     $data['titulo'] = $_POST['titulo'];
     $data['observaciones'] = $_POST['observaciones'];
     $data['fecha'] = Utils::now();
     $data['publicado'] = $_POST['publicado'];
     $data['usuarios_id'] = $uid;
     $db = new DB();
     $db->perform('encuestas', $data);
     $eid = $db->lastInsertedId();
     Elfic::cosRedirect('index2.php?com=encuestas&do=edit&eid=' . $eid);
 }
Ejemplo n.º 2
0
 function setAsistenciaTutor()
 {
     global $uid;
     $curso = (int) $_REQUEST['curso_id'];
     $data['usuario_id'] = $uid;
     $data['tipo_registro'] = $this->getTipoRegistro($uid, $curso);
     $data['fecha_hora'] = Utils::now();
     $data['curso_id'] = $curso;
     $data['comentarios'] = "";
     $data['agendas_tutorias_id'] = 1;
     //$this->_prepareRegistro($data);
     $db = new DB();
     $db->perform(TBL_ASIST_TUT, $data);
 }
Ejemplo n.º 3
0
 public function Process()
 {
     $this->layout_view = null;
     //server side validation
     $this->_name_space = $_POST['name_space'] . '_';
     $this->mode = $_POST['mode'];
     $this->table = $_POST['table'];
     $this->query_action = $_POST['query_action'];
     //check permissions
     if (!_ControllerFront::$session->getPermissions($this->query_action, $this->table)) {
         return;
     }
     $this->channel = $_POST['channel'];
     $this->key = AdaptorMysql::getPrimaryKey($this->table);
     if ($this->query_action == 'update') {
         $this->id = $_POST[$this->_name_space . $this->key];
     } else {
         $this->id = '';
     }
     $this->db = AdaptorMysql::getInstance();
     $q_cols = $this->db->query("SHOW COLUMNS FROM {$this->table}", MYSQL_BOTH);
     $row_data = array();
     //set up error handler here
     $this->errorData = array();
     foreach ($q_cols as $col) {
         $col_type = strtolower($col['Type']);
         $col_ready = false;
         $q_c = array();
         //get all the base config
         $tA = Utils::checkArray(_ControllerFront::$config['cols'], array('column_name' => $col['Field']), true);
         if (is_array($tA)) {
             $q_c = $tA;
         }
         //get anything from the blackbird_cols
         if ($q_sql = $this->db->query("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "cols WHERE column_name = '{$col['Field']}' AND process_module != '' ORDER BY table_name,process_mode")) {
             $q_c = array_merge($q_c, $q_sql);
         }
         // Check process mode
         $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'process_mode' => $this->query_action));
         if (!$q_col) {
             $q_col = Utils::checkArray($q_c, array('table_name' => $this->table, 'process_mode' => ''));
         }
         if (!$q_col) {
             $q_col = Utils::checkArray($q_c, array('table_name' => '*', 'process_mode' => $this->query_action));
             if (!$q_col) {
                 $q_col = Utils::checkArray($q_c, array('table_name' => '*', 'process_mode' => ''));
             }
         }
         $module = $q_col ? $q_col['process_module'] : '';
         switch (true) {
             case $module == 'plugin' || $module == 'file':
                 $options = array();
                 $options['mode'] = $this->query_action;
                 $options['name_space'] = $this->_name_space;
                 $options['db'] = AdaptorMysql::getInstance();
                 if ($this->query_action == "update") {
                     $options['id'] = $this->id;
                 }
                 if ($this->query_action == "insert") {
                     $options['id'] = $this->db->getInsertId($this->table);
                 }
                 $options['col_name'] = $col['Field'];
                 $options['table'] = $this->table;
                 if (isset($_REQUEST[$this->_name_space . $col['Field']])) {
                     $value = $_REQUEST[$this->_name_space . $col['Field']];
                 } else {
                     $value = '';
                 }
                 if (strlen($q_col['process_config']) > 1) {
                     $options = array_merge($options, _ControllerFront::parseConfig($q_col['process_config']));
                 }
                 if ($module == 'plugin') {
                     $t = _ControllerFront::pluginColumnProcess($this->_name_space . $col['Field'], $value, $options);
                     if (isset($t['error'])) {
                         $this->errorData[] = array('field' => $col['Field'], 'error' => $t['error']);
                     } else {
                         if (is_array($t)) {
                             $row_data[] = $t;
                         }
                     }
                 }
                 if ($module == 'file') {
                     $name = $this->_name_space . $col['Field'];
                     $upload = true;
                     if (isset($options['file_validator']) && is_uploaded_file($_FILES[$name]['tmp_name'])) {
                         $t = Utils::validateFile($_FILES[$name], $options['file_validator']);
                         if ($t === true) {
                         } else {
                             if (is_array($t)) {
                                 $r = '<ul>';
                                 foreach ($t as $row) {
                                     $r .= '<li>' . $row . '</li>';
                                 }
                                 $r .= '</ul>';
                                 $this->errorData[] = array('field' => $col['Field'], 'error' => $r);
                                 $upload = false;
                             }
                         }
                     }
                     //if so.. do upload
                     if ($upload === true) {
                         if ($value = Utils::uploadFile($name, $value, $options)) {
                             $row_data[] = array('field' => $options['col_name'], 'value' => $value);
                             if (isset($options['thumbnails'])) {
                                 foreach ($options['thumbnails'] as $thumb) {
                                     $src = WEB_ROOT . 'files/' . $options['table'] . '/' . $options['col_name'] . '/' . $value;
                                     $targ = WEB_ROOT . 'files/' . $options['table'] . '/' . $thumb['output_directory'] . '/image_' . $options['id'] . '.jpg';
                                     Utils::createThumb($src, $targ, $thumb['height'], $thumb['width'], array('quality' => $thumb['quality'], 'mode' => $thumb['mode']));
                                 }
                             }
                         } elseif (isset($_POST[$name . '_delete']) && $_POST[$name . '_delete']) {
                             $row_data[] = array('field' => $options['col_name'], 'value' => '');
                         }
                     }
                 }
                 $col_ready = true;
                 break;
             case $module == 'position':
                 //if we are a position column
                 $where = '';
                 if (strlen($q_col['process_config']) > 1) {
                     $config = _ControllerFront::parseConfig($q_col['process_config']);
                 } else {
                     if (isset($config)) {
                         unset($config);
                     }
                 }
                 $value = $_REQUEST[$this->_name_space . $col['Field']];
                 $nullable = AdaptorMysql::isNullable($this->table, $config['col_constraint']);
                 if ($this->query_action == "update") {
                     //check for constraints from config
                     if (isset($config['col_constraint'])) {
                         //try to find in row_data
                         $foundrow = false;
                         foreach ($row_data as $temprow) {
                             if ($temprow['field'] == $config['col_constraint']) {
                                 $foundrow = true;
                                 if ($nullable && Utils::isNull($_REQUEST[$this->_name_space . $config['col_constraint']])) {
                                     $_v = "IS NULL";
                                 } else {
                                     $_v = " = '" . $temprow['value'] . "'";
                                 }
                                 $where = "WHERE `{$config['col_constraint']}` " . $_v;
                             }
                         }
                         if (!$foundrow) {
                             //check for the $_REQUEST
                             if ($nullable && Utils::isNull($_REQUEST[$this->_name_space . $config['col_constraint']])) {
                                 $_v = "IS NULL";
                             } else {
                                 $_v = " = '" . $_REQUEST[$this->_name_space . $config['col_constraint']] . "'";
                             }
                             $where = "WHERE `{$config['col_constraint']}` " . $_v;
                         }
                     }
                     _ControllerFront::sortPosition($this->table, "SELECT id FROM `{$this->table}` {$where} ORDER BY `{$col['Field']}`", $this->id, $value, $col['Field']);
                 }
                 if ($this->query_action == "insert") {
                     //check for constraints from config
                     if (isset($config)) {
                         //is null
                         if ($nullable && Utils::isNull($_REQUEST[$this->_name_space . $config['col_constraint']])) {
                             $_v = "IS NULL";
                         } else {
                             $_v = " = '" . $_REQUEST[$this->_name_space . $config['col_constraint']] . "'";
                         }
                         $where = "WHERE `{$config['col_constraint']}` " . $_v . " ";
                     }
                     $sql = "SELECT max(`{$col['Field']}`) AS position FROM `{$this->table}` {$where}";
                     trigger_error($sql);
                     $q_pos = $this->db->queryRow($sql);
                     $row_data[] = array("field" => $col['Field'], "value" => $q_pos['position'] + 1);
                 }
                 $col_ready = true;
                 break;
             case $module == 'slug':
                 function checkSlug($slug, $options)
                 {
                     if ($slug != '*' && ($q = $options['db']->query("\n\t\t\t\t\t\t\tSELECT " . $options['col_name'] . "\n\t\t\t\t\t\t\tFROM " . $options['table'] . "\n\t\t\t\t\t\t\tWHERE id != '" . $options['id'] . "'\n\t\t\t\t\t\t\t\tAND " . $options['col_name'] . " = '" . $slug . "'" . $options['where'] . "\n\t\t\t\t\t\t"))) {
                         if (is_numeric($i = substr($slug, strrpos($slug, '_') + 1))) {
                             $slug = substr($slug, 0, strrpos($slug, '_') + 1) . ($i + 1);
                         } else {
                             $slug .= '_1';
                         }
                         return checkSlug($slug, $options);
                     } else {
                         return $slug;
                     }
                 }
                 if (strlen($q_col['process_config']) > 1) {
                     $config = _ControllerFront::parseConfig($q_col['process_config']);
                 } else {
                     if (isset($config)) {
                         unset($config);
                     }
                 }
                 $value = $_REQUEST[$this->_name_space . $col['Field']];
                 if ($this->query_action == 'insert') {
                     $this->id = mysql_insert_id();
                     //$q_pos = $this->db->queryRow("SELECT max($col[Field]) FROM `$this->table` $where");
                     //$this->id = $q_pos[0] + 1;
                 }
                 //check for constraints from config
                 $where = "";
                 if (isset($config['col_constraint'])) {
                     //try to find in row_data
                     foreach ($row_data as $temprow) {
                         if ($temprow['field'] == $config['col_constraint']) {
                             $where = " AND `" . $temprow['field'] . "` = '" . $temprow['value'] . "' ";
                         }
                     }
                 }
                 $value = checkSlug($value, array('col_name' => $col['Field'], 'table' => $this->table, 'id' => $this->id, 'where' => $where, 'db' => $this->db));
                 /*if ($value != '*' && $q = $this->db->query("
                 			SELECT ".$col['Field']."
                 			FROM ".$this->table."
                 			WHERE id != '".$this->id."'
                 				AND ".$col['Field']." = '".$value."'".$where."
                 		")) {
                 			if (is_numeric($i = substr($value,strrpos($value,'_')+1))) $value = substr($value,0,strrpos($value,'_')+1).($i+1);
                 			else $value = $value.'_1';
                 		}*/
                 $row_data[] = array("field" => $col['Field'], "value" => $value);
                 $col_ready = true;
                 break;
             case $module == 'timestamp':
                 $row_data[] = array("field" => $col['Field'], "value" => $col['Field'] == 'created' && $_REQUEST[$this->_name_space . $col['Field']] ? $_REQUEST[$this->_name_space . $col['Field']] : Utils::now());
                 $col_ready = true;
                 break;
             case $col_type == "datetime" || $col_type == "timestamp":
                 //check null
                 if (isset($_REQUEST[$this->_name_space . $col['Field'] . '_isnull'])) {
                     $row_data[] = array('field' => $col['Field'], 'value' => null);
                 } else {
                     $row_data[] = array("field" => $col['Field'], "value" => Utils::assembleDateTime($col['Field'], $this->_name_space));
                 }
                 $col_ready = true;
                 break;
             case $col_type == "date":
                 //
                 if (isset($_REQUEST[$this->_name_space . $col['Field'] . '_isnull'])) {
                     $row_data[] = array('field' => $col['Field'], 'value' => null);
                 } else {
                     $row_data[] = array("field" => $col['Field'], "value" => Utils::assembleDate($col['Field'], $this->_name_space));
                 }
                 $col_ready = true;
                 break;
             case $col_type == "time":
                 $row_data[] = array("field" => $col['Field'], "value" => Utils::assembleTime($col['Field'], $this->_name_space));
                 $col_ready = true;
                 break;
             default:
                 //if we are a generic column
                 if (isset($_REQUEST[$this->_name_space . $col['Field']])) {
                     $row_data[] = array("field" => $col['Field'], "value" => $_REQUEST[$this->_name_space . $col['Field']]);
                 }
                 break;
         }
     }
     $q_table = $this->db->queryRow("SELECT * FROM " . BLACKBIRD_TABLE_PREFIX . "tables WHERE table_name = '{$this->table}'");
     if (strlen($q_table['process_module']) > 3) {
         //$this->cms->pluginTableProcess($this->table,$this->id,$this->query_action);
     } else {
         if (count($this->errorData) == 0) {
             //check nullable
             foreach ($row_data as $key => $row) {
                 if (Utils::isNull($row['value'])) {
                     if (AdaptorMysql::isNullable($this->table, $row['field'])) {
                         $row_data[$key]['value'] = null;
                     }
                 }
             }
             if ($this->query_action == "insert") {
                 $sql = $this->db->insert($this->table, $row_data);
                 $this->id = mysql_insert_id();
             }
             if ($this->query_action == "update") {
                 $key = AdaptorMysql::getPrimaryKey($this->table);
                 $sql = $this->db->update($this->table, $row_data, $key, $this->id);
             }
             $row_data = array();
             $row_data[] = array('field' => 'table_name', 'value' => $this->table);
             $row_data[] = array('field' => 'record_id', 'value' => $this->id);
             $row_data[] = array('field' => 'action', 'value' => $this->query_action);
             $row_data[] = array('field' => 'user_id', 'value' => _ControllerFront::$session->u_id);
             $row_data[] = array('field' => 'sql', 'value' => $sql);
             $row_data[] = array('field' => 'session_id', 'value' => session_id());
             $this->db->insert(BLACKBIRD_TABLE_PREFIX . 'history', $row_data);
             $this->view(array('data' => array('mode' => $this->mode, 'query_action' => $this->query_action, 'channel' => $this->channel, 'name_space' => $_POST['name_space'], 'table' => $this->table, 'id' => $this->id)));
         } else {
             //$GLOBALS['errors'] = $this->errorData;
             $this->view(array('view' => '/_errors/remote', 'data' => array('mode' => $this->mode, 'query_action' => $this->query_action, 'channel' => $this->channel, 'name_space' => $_POST['name_space'], 'table' => $this->table, 'id' => $this->id, 'errors' => $this->errorData)));
         }
     }
     //if we have warnings, feed them back
 }
Ejemplo n.º 4
0
 public function resetPassword($email)
 {
     $user = $this->db->find()->where(['confirmed_at IS NOT' => NULL, 'AND' => [['email' => $email]]])->first();
     if ($user) {
         $reset_token = Str::random(60);
         $req = $this->db->get($user->id);
         $req->reset_token = $reset_token;
         $req->reset_at = Utils::now();
         $this->db->save($req);
         return $user;
     }
     return false;
 }
Ejemplo n.º 5
0
 public function logout()
 {
     //session_save_path(CMS_FILESYSTEM.'tmp');
     session_name("Blackbird_sid");
     session_start();
     $row_data = array();
     $row_data[] = array('field' => 'end_time', 'value' => Utils::now());
     $this->db->update(BLACKBIRD_TABLE_PREFIX . "sessions", $row_data, 'session_id', session_id());
     $_SESSION = array();
     if (isset($_COOKIE["Blackbird_sid"])) {
         setcookie("Blackbird_sid", '', time() - 42000, '/');
     }
     session_destroy();
 }