public function build_director()
 {
     //get data from SQL
     $data = $this->get_data();
     $input = SQLLexical::make_product_list($data['list_product']);
     //use sql builder
     $sql_builder = new SQLBuilder();
     $id_array = array("Name", "Bought", "Price", "Unit");
     foreach ($input as $key => $value) {
         $sql_builder->update('tam_an.product')->set($id_array, $value)->where()->equals('ID', $key)->end_query();
     }
     return $sql_builder->to_string();
 }
$_RULES = array("user_firstname" => Validation::$f->notEmpty_String, "user_lastname" => Validation::$f->notEmpty_String, "user_email" => Validation::$f->Email, "user_schoolname" => Validation::$f->notEmpty_String);
$v = new Validation($_POST, array("user_firstname", "user_lastname", "user_email", "user_schoolname", "user_password", "user_repassword"), $_RULES);
if ($v->fieldsExists()) {
    $setrepassword = Validation::Query($_POST, array("user_password", "user_repassword"));
    $repassword = $setrepassword ? $_POST["user_password"] == $_POST["user_repassword"] : false;
    $email_available = Auth::user_exists($_POST["user_email"]) == 0 || $_POST["user_email"] == $user->user_email;
    if ($v->testAll() && $email_available) {
        $set = $v->export($_MYSQLI, array("user_firstname", "user_lastname", "user_email", "user_schoolname", "user_password"));
        if (false) {
            $set["user_photo_path"] = "";
        }
        if ($repassword) {
            $set["user_password"] = Security::CryptPassword($_POST["user_password"]);
        }
        $statement = new SQLBuilder($_MYSQLI);
        $q = $statement->update('user')->set($set)->where("user_id", "=", Auth::getUserId())->build();
        $r = $_MYSQLI->query($q);
    }
}
$user = Auth::getUser();
/*

$other_query_photo = 'SELECT user_photo_path
				FROM user
				WHERE user_id = '.Auth::getUserId();


$other_result_photo = $_MYSQLI->query($other_query_photo);

$row = $other_result_photo->fetch_object();*/
?>
}
$_RULES = array("question_content" => Validation::$f->notEmpty_String, "question_type" => function ($d) {
    return $d == "checkbox" || $d == "radio";
}, "question_hint" => Validation::$f->String, "question_weight" => function ($d) {
    return is_numeric($d) && $d % 1 == 0 && $d >= 1 && $d <= 5;
});
$v = new Validation($_POST, array("question_content", "question_type", "question_hint", "question_weight"), $_RULES);
if ($own && Validation::Query($_POST, array("indexes", "correct_indexes", "labels")) && $v->fieldsExists()) {
    if ($v->testAll()) {
        $statement = new SQLBuilder($_MYSQLI);
        if ($new) {
            $q = $statement->insertInto('question')->set($v->export(null, array("question_content", "question_type", "question_hint", "question_weight"), array("question_questionnaire_id" => $_GET["qid"], "question_num" => $questionnaire->questionnaire_total_questions + 1)))->build();
            $_MYSQLI->query($q);
            $_GET["id"] = $_MYSQLI->insert_id;
        } else {
            $q = $statement->update('question')->set($v->export(null, array("question_content", "question_type", "question_hint", "question_weight")))->where("question_id", "=", $_GET["id"])->build();
            $_MYSQLI->query($q);
        }
        $insertions = array();
        $correct = array();
        $one_correct = false;
        foreach ($_POST["indexes"] as $k => $val) {
            $correct[$k] = in_array($val, $_POST["correct_indexes"]) ? 1 : 0;
        }
        foreach ($_POST["labels"] as $k => $lbl) {
            if ($lbl != "") {
                $insertions[] = '(NULL, ' . $_GET["id"] . ', \'' . $_MYSQLI->real_escape_string($lbl) . '\', \'' . $correct[$k] . '\')';
                if ($correct[$k]) {
                    $one_correct = true;
                }
            }
Ejemplo n.º 4
0
 public function update(&$data, $where)
 {
     $data = $this->process_data($data);
     $sql = new SQLBuilder($this->conn, $this->get_fully_qualified_table_name());
     $sql->update($data)->where($where);
     $values = $sql->bind_values();
     return $this->conn->query($this->last_sql = $sql->to_s(), $values);
 }
Ejemplo n.º 5
0
 /**
  * Updates records using set in $options
  *
  * Does not instantiate models and therefore does not invoke callbacks
  *
  * Update all using a hash:
  *
  * <code>
  * YourModel::update_all(array('set' => array('name' => "Bob")));
  * </code>
  *
  * Update all using a string:
  *
  * <code>
  * YourModel::update_all(array('set' => 'name = "Bob"'));
  * </code>
  *
  * An options array takes the following parameters:
  *
  * <ul>
  * <li><b>set:</b> String/hash of field names and their values to be updated with
  * <li><b>conditions:</b> Conditions using a string/hash/array</li>
  * <li><b>limit:</b> Limit number of records to update (MySQL & Sqlite only)</li>
  * <li><b>order:</b> A SQL fragment for ordering such as: 'name asc', 'id desc, name asc' (MySQL & Sqlite only)</li>
  * </ul>
  *
  * @params array $options
  * return integer Number of rows affected
  */
 public static function update_all($options = array())
 {
     $table = static::table();
     $conn = static::connection();
     $sql = new SQLBuilder($conn, $table->get_fully_qualified_table_name());
     $sql->update($options['set']);
     if (isset($options['conditions']) && ($conditions = $options['conditions'])) {
         if (is_array($conditions) && !is_hash($conditions)) {
             call_user_func_array(array($sql, 'where'), $conditions);
         } else {
             $sql->where($conditions);
         }
     }
     if (isset($options['limit'])) {
         $sql->limit($options['limit']);
     }
     if (isset($options['order'])) {
         $sql->order($options['order']);
     }
     $values = $sql->bind_values();
     $ret = $conn->query($table->last_sql = $sql->to_s(), $values);
     return $ret->rowCount();
 }
Ejemplo n.º 6
0
 public function update(&$data, $where)
 {
     $data = $this->processData($data);
     $sql = new SQLBuilder($this->conn, $this->getFullyQualifiedTableName());
     $sql->update($data)->where($where);
     $values = $sql->bindValues();
     return $this->conn->query($this->lastSql = $sql->toS(), $values);
 }
$token = ClientLogin::getAuthToken('username', 'password');
$ftclient = new FTClientLogin($token);
//show all tables
echo $ftclient->query(SQLBuilder::showTables());
echo "<br />";
//describe a table
echo $ftclient->query(SQLBuilder::describeTable(358077));
echo "<br />";
//select * from table
echo $ftclient->query(SQLBuilder::select(358077));
echo "<br />";
//select * from table where test=1
echo $ftclient->query(SQLBuilder::select(358077, null, "'test'=1"));
echo "<br />";
//select test from table where test = 1
echo $ftclient->query(SQLBuilder::select(358077, array('test'), "'test'=1"));
echo "<br />";
//select rowid from table
echo $ftclient->query(SQLBuilder::select(358077, array('rowid')));
echo "<br />";
//delete row 401
echo $ftclient->query(SQLBuilder::delete(358077, '401'));
echo "<br />";
//drop table
echo $ftclient->query(SQLBuilder::dropTable(358731));
echo "<br />";
//update table test=1 where rowid=1
echo $ftclient->query(SQLBuilder::update(358077, array('test' => 12), 1));
echo "<br />";
//insert into table (test, test2, 'another test') values (12, 3.3333, 'bob')
echo $ftclient->query(SQLBuilder::insert(358077, array('test' => 12, 'test2' => 3.33333, 'another test' => 'bob')));
Ejemplo n.º 8
0
 public function delete($data)
 {
     $data = $this->process_data($data);
     $sql = new SQLBuilder($this->conn, $this->get_fully_qualified_table_name());
     if (!empty($this->soft_delete_key)) {
         $sql->update($data);
     } else {
         $sql->delete($data);
     }
     $values = $sql->bind_values();
     return $this->conn->query($this->last_sql = $sql->to_s(), $values);
 }
Ejemplo n.º 9
0
    $datetimes = false;
    if ($startdate_instance instanceof DateTime && $enddate_instance instanceof DateTime) {
        $startdate = $startdate_instance->format('U');
        $enddate = $enddate_instance->format('U');
        $datetimes = $enddate > $startdate;
    }
    if ($v->testAll() && $datetimes) {
        $statement = new SQLBuilder($_MYSQLI);
        if ($new) {
            $inserted = true;
            $q = $statement->insertInto('questionnaire')->set($v->export(null, array("questionnaire_title", "questionnaire_description"), array("questionnaire_start_date" => $startdate, "questionnaire_end_date" => $enddate, "questionnaire_user_id" => Auth::getUserId())))->build();
            $_MYSQLI->query($q);
            echo "<html><head><title></title></head><body><script>parent.location.href='form.php?id=" . $_MYSQLI->insert_id . "';</script></body></html>";
            exit;
        } else {
            $q = $statement->update('questionnaire')->set($v->export(null, array("questionnaire_title", "questionnaire_description"), array("questionnaire_start_date" => $startdate, "questionnaire_end_date" => $enddate)))->where("questionnaire_id", "=", $_GET["id"])->build();
            $_MYSQLI->query($q);
            header("Location: frame_form_edit.php?refresh=true&id=" . $_GET["id"]);
            exit;
        }
    }
    if ($v->fail("questionnaire_title")) {
        echo "questionnaire_title fail";
    }
    if ($v->fail("questionnaire_description")) {
        echo "questionnaire_description fail";
    }
    if (!$datetimes) {
        echo "datetimes fail";
    }
}