function makeInsertQuery($arrayCampos, $execute = true, $table = '')
{
    $db = Database::obtain();
    $sql = '';
    foreach ($arrayCampos as $campo) {
        // SI EL POST VALUE NO ES EMPTY
        if (isset($_POST[$campo['name']])) {
            // POST ARRAY
            if (is_array($_POST[$campo['name']])) {
                $_POST[$campo['name']] = implode('[div]', $_POST[$campo['name']]);
                $sql .= $campo['name'] . "='" . trim($_POST[$campo['name']]) . "', ";
            } else {
                // MD5 FOR PASSWORD
                if (isset($campo['inputType']) && $campo['inputType'] == 'password') {
                    $sql .= $campo['name'] . "=MD5('" . trim($_POST[$campo['name']]) . "'), ";
                } elseif (isset($campo['inputType']) && $campo['inputType'] == 'tags') {
                    $sql .= "";
                } elseif (isset($campo['inputType']) && $campo['inputType'] == 'displayfield') {
                    $sql .= "";
                } elseif (isset($campo['selectIsFlag']) && $campo['selectIsFlag'] && $campo['uniqueValue']) {
                    $sql .= $campo['name'] . "='" . tirm($_POST[$campo['name']]) . "', ";
                    sq("update " . $table . " set " . $campo['name'] . " = 0");
                } else {
                    $sql .= $campo['name'] . "='" . trim($_POST[$campo['name']]) . "', ";
                }
            }
        } else {
            if ($campo['allowBlank']) {
                if ($campo['submitValue'] && !$campo['disabled']) {
                    $sql .= $campo['name'] . "='', ";
                } else {
                    $sql .= "";
                }
            }
        }
    }
    $sql = substr($sql, 0, strlen($sql) - 2);
    $sql = "INSERT INTO " . $table . " SET " . $sql . ", dateLastUpdate=NOW(), dateInsert=NOW()";
    if ($execute) {
        return $db->query($sql);
    } else {
        pr("warning! executeQuerys = false");
        die(pr($sql));
    }
}
Beispiel #2
0
 public function update()
 {
     $data['user_id'] = isset($this->input['user_id']) ? trim($this->input['user_id']) : $this->marklib->checkUserExit();
     $data['kind_id'] = tirm($this->input['kind_id']);
     $mark_id = trim($this->input['mark_id']);
     $marks = explode(',', $mark_id);
     $q = array();
     foreach ($marks as $k => $v) {
         if (empty($v)) {
             $this->errorOutput("你的设置里的参数有空字段");
         }
         $res = $this->marklib->get('name', 'nid as mark_id', array('nid' => $v, 'state' => 1, 'action' => 1), 0, 1, array());
         if (!$res) {
             $this->errorOutput("你的设置里的参数有禁止字段");
         }
         $q[$v] = $v;
     }
     $mark_id = implode(',', $q);
     $new_kind_id = tirm($this->input['new_kind_id']);
     $result = $this->marklib->get('kind_action', 'kind_id,user_id,mark_id', array('user_id' => $data['user_id'], 'kind_id' => $data['kind_id'], 'mark_id' => $mark_id), 0, count($q), array());
     $this->setXmlNode('kind', 'move');
     $arr = array();
     if ($result) {
         foreach ($result as $k => $v) {
             if (in_array($v['mark_id'], $q)) {
                 if ($this->marklib->delete('kind_action', $v)) {
                     $this->updateKindSigns(array('user_id' => $data['user_id'], 'kind_id' => $data['kind_id']), -1, 1);
                 }
                 $ret = $this->marklib->get('kind_action', 'kind_id,user_id,mark_id', array('user_id' => $data['user_id'], 'kind_id' => $new_kind_id, 'mark_id' => $v['mark_id']), 0, 1, array());
                 if (!$ret) {
                     if ($this->marklib->insert('kind_action', array('user_id' => $data['user_id'], 'kind_id' => $new_kind_id, 'mark_id' => $v['mark_id'], 'create_time' => TIMENOW))) {
                         $this->updateKindSigns(array('user_id' => $data['user_id'], 'kind_id' => $new_kind_id), 1, 1);
                     }
                 }
                 $this->addItem_withkey($v['mark_id'], true);
                 unset($q[$v['mark_id']]);
             }
         }
     }
     if ($q) {
         $data['kind_id'] = $new_kind_id;
         foreach ($q as $k => $v) {
             $try = false;
             $data['mark_id'] = $v;
             $data['create_time'] = TIMENOW;
             if ($this->marklib->insert('kind_action', $data)) {
                 $this->updateKindSigns(array('user_id' => $data['user_id'], 'kind_id' => $new_kind_id), 1, 1);
                 $try = true;
             }
             $this->addItem_withkey($v, $try);
         }
     }
 }