/**
  * 将数据添加到数据库
  * @return boolean
  */
 public function insertAction()
 {
     /**
      * 记录日志
      */
     $log = "游戏类别添加入库\n\nServerIp:\n" . $this->request->getServer('SERVER_ADDR') . "\n\nGET:\n" . var_export($_GET, true) . "\n\nPOST:\n" . var_export($_POST, true);
     $this->oLogManager->push('log', $log);
     //检查权限
     $this->manager->checkMenuPermission($this->sign, Widget_Manager::MENU_PURVIEW_INSERT);
     $params = $this->request->from('name', 'desc');
     if (empty($params['name'])) {
         $response = array('errno' => 1);
         echo json_encode($response);
         return false;
     }
     if ($this->oClass->nameExists($params['name'])) {
         $response = array('errno' => 2);
         echo json_encode($response);
         return false;
     }
     $res = $this->oClass->insert($params);
     $response = $res ? array('errno' => 0) : array('errno' => 9);
     echo json_encode($response);
     return true;
 }
Example #2
0
 /**
  * Test role synchronisation
  */
 public function testRoleSynchronisation()
 {
     // create a first test ACL role
     $query = $this->model->insert()->into('acl_role')->values(['name' => 'test role 1']);
     $statement = $this->model->prepareStatementForSqlObject($query);
     $statement->execute();
     $this->aclRolesIds[] = $this->model->getAdapter()->getDriver()->getLastGeneratedValue();
     // create a test user
     $query = $this->model->insert()->into('user_list')->values(['nick_name' => Rand::getString(32), 'email' => Rand::getString(32), 'role' => $this->aclRolesIds[0]]);
     $statement = $this->model->prepareStatementForSqlObject($query);
     $statement->execute();
     $this->usersIds[] = $this->model->getAdapter()->getDriver()->getLastGeneratedValue();
     // delete the created ACL role
     $query = $this->model->delete()->from('acl_role')->where(['id' => $this->aclRolesIds[0]]);
     $statement = $this->model->prepareStatementForSqlObject($query);
     $statement->execute();
     // fire the delete ACL role event
     AclEvent::fireDeleteAclRoleEvent($this->aclRolesIds[0]);
     // check the created test user's role
     $select = $this->model->select();
     $select->from('user_list')->columns(['role'])->where(['user_id' => $this->usersIds[0]]);
     $statement = $this->model->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $result = $resultSet->initialize($statement->execute());
     // user must be a default member
     $this->assertEquals($result->current()['role'], AclBaseModel::DEFAULT_ROLE_MEMBER);
 }
Example #3
0
 public function create($insert_array)
 {
     try {
         $this->db->insert("`" . $this->table . "`", $insert_array);
         return $this->db->lastInsertId();
     } catch (Exception $e) {
         return false;
     }
 }
Example #4
0
 public function insertAction()
 {
     $bind = $this->request->from('name', 'currency_rate', 'is_abroad');
     $bind['is_abroad'] = $bind['is_abroad'] ? $bind['is_abroad'] : 1;
     $res = $this->oArea->insert($bind);
     $response = $res ? array('errno' => 0) : array('errno' => 9);
     echo json_encode($response);
     return true;
 }
Example #5
0
 /**
  * Saves user data into the users table
  * @param $data
  * @return bool
  */
 public function saveData($data)
 {
     try {
         $this->tableGateway->insert($data);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Example #6
0
 public function insertAction()
 {
     $bind = $this->request->from('ResearchName', 'ResearchContent');
     if ($bind['ResearchName'] == '') {
         $response = array('errno' => 3);
     } else {
         $res = $this->oResearch->insert($bind);
         $response = $res ? array('errno' => 0) : array('errno' => 9);
     }
     echo json_encode($response);
     return true;
 }
Example #7
0
 /**
  * This function update and insert user record
  * @param \Music\Model\User $user
  * @throws \Exception
  */
 public function saveUser(User $user, $user_id)
 {
     $data = array('username' => $user->getUsername(), 'password' => md5($user->getPassword()), 'role' => $user->getRole(), 'fullname' => $user->getFullName());
     $user_id = (int) $user->getUserId();
     if (!$user_id) {
         $this->tableGateway->insert($data);
     } else {
         if ($user_id) {
             $this->tableGateway->update($data, array('user_id' => $user_id));
         } else {
             throw new \Exception('Form id does not exist');
         }
     }
 }
Example #8
0
 public function insertAction()
 {
     //检查权限
     $this->manager->checkMenuPermission($this->sign, Widget_Manager::MENU_PURVIEW_INSERT);
     $bind = $this->request->from('name', 'SourceTypeId');
     if ($bind['name'] == '') {
         $response = array('errno' => 2);
     } else {
         $res = $this->oSourceType->insert($bind);
         $response = $res ? array('errno' => 0) : array('errno' => 9);
     }
     echo json_encode($response);
     return true;
 }
 /**
  * Returns the template bit
  *
  * @access	public
  * @return	string
  */
 public function getTemplate()
 {
     //-----------------------------------------
     // Clear old
     //-----------------------------------------
     $this->_clearSessions($this->member->ip_address);
     //-----------------------------------------
     // Create new ID
     //-----------------------------------------
     $captcha_unique_id = md5(uniqid(time()));
     $captcha_string = "";
     //-----------------------------------------
     // Create new string
     //-----------------------------------------
     /**
      * Array of characters 
      * Removed: 0, o, O, 1, l, I, i, L (because they're hard to differentiate)
      */
     $array_of_chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9');
     /* Get 6 random characters */
     for ($i = 0; $i < 6; $i++) {
         $idx = mt_rand(0, count($array_of_chars) - 1);
         $captcha_string .= $array_of_chars[$idx];
     }
     //-----------------------------------------
     // Add to the DB
     //-----------------------------------------
     $this->DB->insert('captcha', array('captcha_unique_id' => $captcha_unique_id, 'captcha_string' => $captcha_string, 'captcha_ipaddress' => $this->member->ip_address, 'captcha_date' => time()));
     /* Make available */
     $this->captchaKey = $captcha_unique_id;
     //-----------------------------------------
     // Return Template Bit
     //-----------------------------------------
     return $this->registry->output->getTemplate('global_other')->captchaGD($captcha_unique_id);
 }
 /**
  * Populate the donation stats for every day of the current fundraiser
  *
  * Note that if you are running more than one fundraiser at once, you'll want to use 
  * populateDays instead of updateDays.
  * Note that these summaries exclude amounts that are not between the mimumum and maximum
  * donation amounts. This is because every once in a while we have to condense multiple
  * donations that may span several days into a single donation for CiviCRM consumption.
  */
 public function updateDays()
 {
     global $egFundraiserStatisticsFundraisers, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum;
     $mostRecentFundraiser = end($egFundraiserStatisticsFundraisers);
     $start = $mostRecentFundraiser['start'];
     $end = $mostRecentFundraiser['end'];
     $begin = time();
     $records = 0;
     $insertArray = array();
     $this->output("Writing data to public_reporting_days...\n");
     $conditions = array('received >= ' . $this->dbpr->addQuotes(wfTimestamp(TS_UNIX, strtotime($start))), 'received <= ' . $this->dbpr->addQuotes(wfTimestamp(TS_UNIX, strtotime($end) + 24 * 60 * 60)), 'converted_amount >= ' . $egFundraiserStatisticsMinimum, 'converted_amount <= ' . $egFundraiserStatisticsMaximum);
     // Get the data for a fundraiser
     $result = $this->dbpr->select('public_reporting', array("DATE_FORMAT( FROM_UNIXTIME( received ),'%Y-%m-%d' ) AS date", 'sum( converted_amount ) AS total', 'count( * ) AS number', 'avg( converted_amount ) AS average', 'max( converted_amount ) AS maximum'), $conditions, __METHOD__, array('ORDER BY' => 'received', 'GROUP BY' => "DATE_FORMAT( FROM_UNIXTIME( received ),'%Y-%m-%d' )"));
     while ($row = $this->dbpr->fetchRow($result)) {
         // Add it to the insert array
         $insertArray[] = array('prd_date' => $row['date'], 'prd_total' => $row['total'], 'prd_number' => $row['number'], 'prd_average' => $row['average'], 'prd_maximum' => $row['maximum'], 'prd_insert_timestamp' => time());
         $records++;
     }
     if ($records > 0) {
         // Empty the table of previous totals for this fundraiser
         $res = $this->dbw->delete('public_reporting_days', array('prd_date >= ' . $this->dbpr->addQuotes(wfTimestamp(TS_DB, strtotime($start))), 'prd_date <= ' . $this->dbpr->addQuotes(wfTimestamp(TS_DB, strtotime($end)))));
         // Insert the new totals
         $res = $this->dbw->insert('public_reporting_days', $insertArray, __METHOD__);
         // Wait for the databases to sync
         wfWaitForSlaves();
     }
     $lag = time() - $begin;
     $this->output("Updated " . $records . " rows. ({$lag} seconds)\n");
     $this->output("Done.\n");
 }
Example #11
0
 /**
  * Add a new element in the tree near element with number id.
  *
  * @param integer $ID Number of a parental element
  * @param array $condition Array structure: array('and' => array('id = 0', 'id2 >= 3'), 'or' => array('sec = \'www\'', 'sec2 <> \'erere\'')), etc where array key - condition (AND, OR, etc), value - condition string
  * @param array $data Contains parameters for additional fields of a tree (if is): array('filed name' => 'importance', etc)
  * @return integer Inserted element id
  */
 function InsertNear($ID, $condition = '', $data = array())
 {
     $node_info = $this->GetNodeInfo($ID);
     if (FALSE === $node_info) {
         return FALSE;
     }
     list($leftId, $rightId, $level, $parent) = $node_info;
     $data[$this->table_left] = $rightId + 1;
     $data[$this->table_right] = $rightId + 2;
     $data[$this->table_level] = $level;
     $data[$this->table_parent] = $section_id;
     if (!empty($condition)) {
         $condition = $this->_PrepareCondition($condition);
     }
     $sql = 'UPDATE ' . $this->table . ' SET ' . $this->table_left . ' = CASE WHEN ' . $this->table_left . ' > ' . $rightId . ' THEN ' . $this->table_left . ' + 2 ELSE ' . $this->table_left . ' END, ' . $this->table_right . ' = CASE WHEN ' . $this->table_right . '> ' . $rightId . ' THEN ' . $this->table_right . ' + 2 ELSE ' . $this->table_right . ' END, ' . $this->table_parent . ' = ' . $parent . 'WHERE ' . $this->table_right . ' > ' . $rightId;
     $sql .= $condition;
     //$this->db->beginTransaction();
     //try{
     $res = $db->query($sql);
     $this->db->insert($this->table, $data);
     $id = $this->db->lastInsertId();
     //$this->db->commit();
     return $id;
     //}
     //catch (Exception $e){
     //$this->db->rollBack();
     //}
 }
 /**
  * private method that handles creating new default templates
  *
  * @param string $template_pack This corresponds to a template pack class reference which will contain information about where to obtain the templates.
  * @return mixed (array|bool)            success array or false.
  */
 private function _create_new_templates($template_pack)
 {
     $this->_set_templates($template_pack);
     //necessary properties are set, let's save the default templates
     if (empty($this->_GRP_ID)) {
         $main_template_data = array('MTP_messenger' => $this->_messenger->name, 'MTP_message_type' => $this->_message_type->name, 'MTP_is_override' => 0, 'MTP_deleted' => 0, 'MTP_is_global' => 1, 'MTP_user_id' => EEH_Activation::get_default_creator_id(), 'MTP_is_active' => 1);
         //let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID
         $grp_id = $this->_EEM_data->insert($main_template_data);
         if (empty($grp_id)) {
             return $grp_id;
         }
         $this->_GRP_ID = $grp_id;
     }
     $template_data = array('GRP_ID' => $this->_GRP_ID);
     foreach ($this->_contexts as $context => $details) {
         foreach ($this->_fields as $field => $field_type) {
             if ($field != 'extra') {
                 $template_data['MTP_context'] = $context;
                 $template_data['MTP_template_field'] = $field;
                 $template_data['MTP_content'] = $this->_templates[$context][$field];
                 $MTP = EEM_Message_Template::instance()->insert($template_data);
                 if (!$MTP) {
                     EE_Error::add_error(sprintf(__('There was an error in saving new template data for %s messenger, %s message type, %s context and %s template field.', 'event_espresso'), $this->_messenger->name, $this->_message_type->name, $context, $field), __FILE__, __FUNCTION__, __LINE__);
                     return false;
                 }
             }
         }
     }
     $success_array = array('GRP_ID' => $this->_GRP_ID, 'MTP_context' => key($this->_contexts));
     return $success_array;
 }
Example #13
0
 /**
  * insert a new config in the database
  *
  * @param   object  &$config    reference to the {@link XoopsConfigItem}
  */
 function insertConfig(&$config)
 {
     if (!$this->_cHandler->insert($config)) {
         return false;
     }
     $options =& $config->getConfOptions();
     $count = count($options);
     $conf_id = $config->getVar('conf_id');
     for ($i = 0; $i < $count; $i++) {
         $options[$i]->setVar('conf_id', $conf_id);
         if (!$this->_oHandler->insert($options[$i])) {
             foreach ($options[$i]->getErrors() as $msg) {
                 $config->setErrors($msg);
             }
         }
     }
     if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
         unset($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
     }
     xoops_load("cache");
     $key = "config_" . intval($config->getVar('conf_modid')) . "_" . intval($config->getVar('conf_catid'));
     if (XoopsCache::read($key)) {
         XoopsCache::delete($key);
     }
     return true;
 }
Example #14
0
 /**
  * Save news object to data source
  * 
  * @param integer $id news identifier
  * @param array $data news data
  * @param string $file_name file name of news image upload 
  * @param string $video_name file name of news video upload
  * @return integer
  */
 public function save_news($id, $data, $file_name = "", $video_name = "")
 {
     if (empty($id)) {
         if (empty($data["date_add"])) {
             $data["date_add"] = date("Y-m-d H:i:s");
         }
         $this->DB->insert(NEWS_TABLE, $data);
         $id = $this->DB->insert_id();
     } else {
         $this->DB->where('id', $id);
         $this->DB->update(NEWS_TABLE, $data);
     }
     if (!empty($file_name) && !empty($id) && isset($_FILES[$file_name]) && is_array($_FILES[$file_name]) && is_uploaded_file($_FILES[$file_name]["tmp_name"])) {
         $news_data = $this->get_news_by_id($id);
         $news_data = $this->format_single_news($news_data);
         $this->CI->load->model("Uploads_model");
         $img_return = $this->CI->Uploads_model->upload($this->upload_config_id, $news_data["prefix"], $file_name);
         if (empty($img_return["errors"])) {
             $img_data["img"] = $img_return["file"];
             $this->save_news($id, $img_data);
         }
     }
     if (!empty($video_name) && !empty($id) && isset($_FILES[$video_name]) && is_array($_FILES[$video_name]) && is_uploaded_file($_FILES[$video_name]["tmp_name"])) {
         if (!isset($news_data)) {
             $news_data = $this->get_news_by_id($id);
             $news_data = $this->format_single_news($news_data);
         }
         $this->CI->load->model("Video_uploads_model");
         $video_data = array("name" => $news_data["name"], "description" => $news_data["annotation"]);
         $video_return = $this->CI->Video_uploads_model->upload($this->video_config_id, $news_data["prefix"], $video_name, $id, $video_data);
     }
     return $id;
 }
Example #15
0
 /**
  * Save alert
  * @param array $data
  * @return boolean
  */
 public function save_alert($id, $data)
 {
     if (!$id) {
         $data["date_add"] = date("Y-m-d H:i:s");
         $this->DB->insert(SPAM_ALERTS_TABLE, $data);
         $id = $this->DB->insert_id();
         $type = $this->Spam_type_model->get_type_by_id($data['id_type']);
         $save_data['obj_count'] = $type["obj_count"] + 1;
         $save_data['obj_need_approve'] = $type["obj_need_approve"] + 1;
         $this->CI->Spam_type_model->save_type($type['id'], $save_data);
     } else {
         $fields = array_flip($this->fields);
         foreach ($data as $key => $value) {
             if (!isset($fields[$key])) {
                 unset($data[$key]);
             }
         }
         if (empty($data)) {
             return false;
         }
         $this->DB->where("id", $id);
         $this->DB->update(SPAM_ALERTS_TABLE, $data);
     }
     return $id;
 }
 /**
  * 将数据入库
  * @return unknown_type
  */
 public function insertAction()
 {
     /**
      * 记录日志
      */
     $log = "合作商添加入库\n\nServerIp:\n" . $this->request->getServer('SERVER_ADDR') . "\n\nGET:\n" . var_export($_GET, true) . "\n\nPOST:\n" . var_export($_POST, true);
     $this->oLogManager->push('log', $log);
     //检查权限
     $this->manager->checkMenuPermission($this->sign, Widget_Manager::MENU_PURVIEW_INSERT);
     $bind = $this->request->from('name', 'notes');
     if (!empty($this->request->newid)) {
         $bind['PartnerId'] = $this->request->newid;
     }
     if (!empty($bind['notes'])) {
         $bind['notes'] = json_encode($bind['notes']);
     }
     if (empty($bind['name'])) {
         $response = array('errno' => 2);
         echo json_encode($response);
         return false;
     }
     $res = $this->oPartner->insert($bind);
     if ($res) {
         $response = array('errno' => 0);
         $this->oPartner->reBuildPartnerConfig();
     } else {
         $response = array('errno' => 9);
     }
     echo json_encode($response);
     return true;
 }
 /**
  * Save promo object to data source
  * 
  * @param integer $id_lang language identifier
  * @param array $data promo data
  * @param string $img_file photo upload
  * @param string $flash_file flash upload
  * @return
  */
 public function save_promo($id_lang, $data, $img_file = '', $flash_file = '')
 {
     if (!$id_lang) {
         return false;
     }
     $data['id_lang'] = $id_lang;
     if (!$this->exists_promo($id_lang)) {
         $this->DB->insert(CONTENT_PROMO_TABLE, $data);
     } else {
         $this->DB->where('id_lang', $id_lang);
         $this->DB->update(CONTENT_PROMO_TABLE, $data);
     }
     if (!empty($img_file) && isset($_FILES[$img_file]) && is_array($_FILES[$img_file]) && is_uploaded_file($_FILES[$img_file]["tmp_name"])) {
         $this->CI->load->model("Uploads_model");
         $img_return = $this->CI->Uploads_model->upload($this->upload_gid, $id_lang . "/", $img_file);
         if (empty($img_return["errors"])) {
             $img_data["promo_image"] = $img_return["file"];
             $this->save_promo($id_lang, $img_data);
         }
     }
     if (!empty($flash_file) && isset($_FILES[$flash_file]) && is_array($_FILES[$flash_file]) && is_uploaded_file($_FILES[$flash_file]["tmp_name"])) {
         $this->CI->load->model("File_uploads_model");
         $flash_return = $this->CI->File_uploads_model->upload($this->file_upload_gid, $id_lang . "/", $flash_file);
         if (empty($flash_return["errors"])) {
             $flash_data["promo_flash"] = $flash_return["file"];
             $this->save_promo($id_lang, $flash_data);
         }
     }
     return true;
 }
Example #18
0
 /**
  * Add link
  * @param string $type_gid
  * @param integer $link_1
  * @param integer $link_2
  */
 public function add_link($type_gid, $link_1, $link_2)
 {
     $link_1 = intval($link_1);
     $link_2 = intval($link_2);
     if (!$link_1 || !$link_2) {
         return false;
     }
     $type = $this->get_linker_type_by_gid($type_gid);
     if (!$type) {
         return false;
     }
     if ($type["unique_type"] != 'no') {
         //// need to get links count, if links are unique
         $link_count = $this->get_links_simple_count($type_gid, $link_1, $link_2);
     }
     if ($type["unique_type"] == 'no' || $link_count == 0) {
         $data = array('id_link_1' => $link_1, 'id_link_2' => $link_2, 'date_add' => date("Y-m-d H:i:s"));
         if (!$type["separated"]) {
             $data["id_type"] = $type["id"];
         }
         $this->DB->insert($type["table_name"], $data);
     } elseif ($type["unique_type"] == 'update') {
         if (!$type["separated"]) {
             $this->DB->where('id_type', $type["id"]);
         }
         $this->DB->where('id_link_1', $link_1);
         $this->DB->where('id_link_2', $link_2);
         $data = array('date_add' => date("Y-m-d H:i:s"));
         $this->DB->update($type["table_name"], $data);
     }
     return;
 }
Example #19
0
 /**
  * Test acl by date
  */
 public function testAclByDate()
 {
     $role = AclModelBase::DEFAULT_ROLE_MEMBER;
     $testResources = ['test_application_settings_administration', 'test_application_modules_administration'];
     $this->addAclResources($testResources, true, $role);
     $currentTime = time();
     // add acl resources connections settings
     foreach ($this->aclResourcesConnections as $connectId) {
         $query = $this->aclModelBase->insert()->into('acl_resource_connection_setting')->values(['connection_id' => $connectId, 'user_id' => $this->userId, 'date_start' => $currentTime, 'date_end' => $currentTime + 1]);
         $statement = $this->aclModelBase->prepareStatementForSqlObject($query);
         $statement->execute();
     }
     $this->initAcl($role);
     // all created acl resources must be active
     foreach ($testResources as $resource) {
         $this->assertTrue(AclService::checkPermission($resource));
     }
     // wait two seconds and check acl resources again
     sleep(2);
     $this->initAcl($role);
     // now all created acl resources must be expired
     foreach ($testResources as $resource) {
         $this->assertFalse(AclService::checkPermission($resource));
     }
 }
Example #20
0
 /**
  * 新增数据
  *
  * @author          liu21st <*****@*****.**>
  * @lastmodify      2013-01-21 14:47:00 by mrmsl
  *
  * @param mixed   $data    数据
  * @param array   $options 参数表达式
  * @param boolean $replace 是否replace
  *
  * @return bool|int 新增成功,返回true或自增id,否则返回false
  */
 public function add($data = '', $options = array(), $replace = false)
 {
     if (empty($data)) {
         if (!empty($this->_data)) {
             //没有传递数据,获取当前数据对象的值
             $data = $this->_data;
             $this->_data = array();
             //重置数据
         } else {
             $this->_error = L('_DATA_TYPE_INVALID_');
             return false;
         }
     }
     $options = $this->_parseOptions($options);
     //分析表达式
     $data = $this->_facade($data);
     //数据处理
     if (false === $this->_beforeInsert($data, $options)) {
         return false;
     }
     $result = $this->_db->insert($data, $options, $replace);
     //写入数据到数据库
     if (false !== $result && ($insert_id = $this->getLastInsertID())) {
         //自增主键返回插入ID
         $data[$this->getPk()] = $insert_id;
         $this->_afterInsert($data, $options);
         return $insert_id;
     }
     return $result;
 }
Example #21
0
 public function insert($table, array $cols)
 {
     if (empty($this->_database)) {
         return false;
     }
     return $this->_database->insert($table, $cols);
 }
 /**
  * Write
  *
  * Writes (create / update) session data
  *
  * @param	string	$session_id	Session ID
  * @param	string	$session_data	Serialized session data
  * @return	bool
  */
 public function write($session_id, $session_data)
 {
     // Was the ID regenerated?
     if ($session_id !== $this->_session_id) {
         if (!$this->_release_lock() or !$this->_get_lock($session_id)) {
             return FALSE;
         }
         $this->_row_exists = FALSE;
         $this->_session_id = $session_id;
     } elseif ($this->_lock === FALSE) {
         return FALSE;
     }
     if ($this->_row_exists === FALSE) {
         $insert_data = array('id' => $session_id, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'timestamp' => time(), 'data' => $this->_platform === 'postgre' ? base64_encode($session_data) : $session_data);
         if ($this->_db->insert($this->_config['save_path'], $insert_data)) {
             $this->_fingerprint = md5($session_data);
             return $this->_row_exists = TRUE;
         }
         return FALSE;
     }
     $this->_db->where('id', $session_id);
     if ($this->_config['match_ip']) {
         $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']);
     }
     $update_data = array('timestamp' => time());
     if ($this->_fingerprint !== md5($session_data)) {
         $update_data['data'] = $this->_platform === 'postgre' ? base64_encode($session_data) : $session_data;
     }
     if ($this->_db->update($this->_config['save_path'], $update_data)) {
         $this->_fingerprint = md5($session_data);
         return TRUE;
     }
     return FALSE;
 }
Example #23
0
 /**
  * Save type
  * @param array $data
  * @return boolean
  */
 public function save_type($id, $data)
 {
     if (!$id) {
         if (!isset($data["gid"]) || !$data["gid"]) {
             return false;
         }
         $data["gid"] = preg_replace("/[^a-z_]/", "", strtolower($data["gid"]));
         $type = $this->get_type_by_id($data["gid"]);
         if ($type) {
             return $type["id"];
         }
         $this->DB->insert(SPAM_TYPES_TABLE, $data);
         $id = $this->DB->insert_id();
     } else {
         $fields = array_flip($this->fields);
         foreach ($data as $key => $value) {
             if (!isset($fields[$key])) {
                 unset($data[$key]);
             }
         }
         if (empty($data)) {
             return false;
         }
         $this->DB->where("id", $id);
         $this->DB->update(SPAM_TYPES_TABLE, $data);
     }
     return $id;
 }
Example #24
0
 /**
  * Inserts data to the database
  *
  * @param string $table
  * @param array $data
  * @return int
  */
 function save($table, $data)
 {
     //remove csrf
     unset($data['csrf']);
     $this->db->insert($table, $data);
     return $this->db->lastInsertId();
 }
Example #25
0
 public function insert($data)
 {
     $sql = self::$db->insert($this->_tableName, array_merge($data, $this->_autoData));
     //		echo $sql;die;
     $this->_reset_write();
     return self::$db->query($sql)->insert_id();
 }
Example #26
0
 /**
  * Table insert method
  *
  * @param  object   	A KDatabaseRow object
  * @return bool|integer Returns the number of rows inserted, or FALSE if insert query was not executed.
  */
 public function insert(KDatabaseRowInterface $row)
 {
     //Create commandchain context
     $context = $this->getCommandContext();
     $context->operation = KDatabase::OPERATION_INSERT;
     $context->data = $row;
     $context->table = $this->getBase();
     $context->query = null;
     if ($this->getCommandChain()->run('before.insert', $context) !== false) {
         //Filter the data and remove unwanted columns
         $data = $this->filter($context->data->getData(), true);
         //Get the data and apply the column mappings
         $data = $this->mapColumns($data);
         //Execute the insert query
         $context->insert_id = $this->_database->insert($context->table, $data);
         if ($context->insert_id !== false) {
             $data[$this->getIdentityColumn()] = $context->insert_id;
             //Reverse apply the column mappings and set the data in the row
             $context->data->setData($this->mapColumns($data, true), false);
             //Set the row status
             $context->data->setStatus(KDatabase::STATUS_INSERTED);
         } else {
             $context->data->setStatus(KDatabase::STATUS_FAILED);
         }
         $this->getCommandChain()->run('after.insert', $context);
     }
     return $context->insert_id;
 }
Example #27
0
 public function insertAction()
 {
     //检查权限
     $this->manager->checkMenuPermission($this->sign, Widget_Manager::MENU_PURVIEW_INSERT);
     $bind = $this->request->from('CageCode', 'Comment', 'Depot', 'Current', 'Size', 'X');
     //echo "<pre>";
     //print_r($bind);
     $bind['DepotId'] = $bind['Depot'];
     unset($bind['Depot']);
     $bind['CageCode'] = trim($bind['CageCode']);
     $bind['Comment'] = trim($bind['Comment']);
     $bind['Current'] = sprintf("%.2f", $bind['Current']);
     $bind['ActualCurrent'] = 0;
     $bind['Size'] = intval($bind['Size']);
     $bind['X'] = trim($bind['X']);
     $bind['Y'] = 0;
     $bind['Udate'] = time();
     if ($bind['CageCode'] == '') {
         $response = array('errno' => 2);
     } elseif ($this->oCage->getRowByCageCode($bind['CageCode'])) {
         $response = array('errno' => 6);
     } elseif (!$bind['DepotId']) {
         $response = array('errno' => 3);
     } elseif (!$bind['Current']) {
         $response = array('errno' => 4);
     } elseif (!$bind['Size']) {
         $response = array('errno' => 5);
     } else {
         $res = $this->oCage->insert($bind);
         $response = $res ? array('errno' => 0) : array('errno' => 9);
     }
     echo json_encode($response);
     return true;
 }
 /**
  * Insert node
  *
  * @param integer $level
  * @param integer $nearKey
  * @param array $data
  * @param array $filter
  * @param boolean $useTransaction
  * @return integer|string
  */
 protected function insertNode($level, $nearKey, array $data, array $filter = [], $useTransaction = true)
 {
     $insertId = 0;
     try {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         }
         $this->tableGateway->update([$this->left => new Expression('IF (' . $this->left . ' > ?, ' . $this->left . ' + 2, ' . $this->left . ')', [$nearKey]), $this->right => new Expression('IF (' . $this->right . '  > ?, ' . $this->right . ' + 2, ' . $this->right . ')', [$nearKey])], [(new Predicate())->greaterThanOrEqualTo($this->right, $nearKey)] + $filter);
         $leftKey = $nearKey + 1;
         $rightKey = $nearKey + 2;
         $level = $level + 1;
         // insert a new node
         $this->tableGateway->insert([$this->left => $leftKey, $this->right => $rightKey, $this->level => $level] + $data);
         $insertId = $this->tableGateway->getLastInsertValue();
         // update parent info
         if (false !== ($parent = $this->getParentNode($leftKey, $rightKey, $level, $filter))) {
             $this->tableGateway->update([$this->parent => $parent[$this->nodeId]], [$this->nodeId => $insertId]);
         }
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
         }
     } catch (Exception $e) {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         }
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return $insertId;
 }
 /**
  * Add setting
  *
  * @param string 
  * @param array $settingValues
  * @param integer $moduleId
  * @return void
  */
 protected function addSetting($setting, array $settingValues = [], $moduleId = 1)
 {
     $settingData = ['name' => $setting, 'module' => $moduleId];
     $query = $this->settingModel->insert()->into('application_setting')->values($settingData);
     $statement = $this->settingModel->prepareStatementForSqlObject($query);
     $statement->execute();
     $settingId = $this->settingModel->getAdapter()->getDriver()->getLastGeneratedValue();
     // add setting values
     if ($settingValues) {
         foreach ($settingValues as $settingValue) {
             // insert setting value
             $query = $this->settingModel->insert()->into('application_setting_value')->values(array_merge($settingValue, ['setting_id' => $settingId]));
             $statement = $this->settingModel->prepareStatementForSqlObject($query);
             $statement->execute();
         }
     }
 }
Example #30
0
 /**
  * Event: new_faq
  * Triggered after FAQ addition
  * @param xhelpTicket $ticket Ticket used as base for FAQ
  * @param xhelpFaq $faq FAQ that was added
  */
 function new_faq($ticket, $faq)
 {
     global $xoopsUser;
     $logMessage =& $this->_hLog->create();
     $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
     $logMessage->setVar('ticketid', $ticket->getVar('id'));
     $logMessage->setVar('action', sprintf(_XHELP_LOG_NEWFAQ, $faq->getVar('subject')));
     return $this->_hLog->insert($logMessage, true);
 }