function creer_nouvelle_equipe($nom_equipe, $image_equipe) { global $bdd; global $creer_nouvelle_equipe; $req = $bdd->prepare($creer_nouvelle_equipe); if (!$req->execute(array('nom_equipe' => $_POST['nom_equipe'], 'image_equipe' => $image_equipe))) { error_sql($req); } else { log2("Equipe ajouté : " . $nom_equipe); } }
function assign_order($order) { //assign an order to the user //return true/false on success/failure if (!$order instanceof Order) { log2('order is not an instance of Order when calling assign_order for a user'); return false; } $this->order = $order; return $order->assign_user($this); }
static function find($id) { $id = intval($id); if (empty($id)) { return false; } $result = sql("SELECT * FROM products WHERE id = {$id}", SQL_SINGLE_ROW); if (!$result) { log2("Invalid SQL query -- " . mysql_error() . ": id = {$id}"); return false; } $ret = new Product($result); return $ret; }
function getShannonEntropy($s) { $n = 0; $occ = array(); for ($c_ = 0; $c_ < strlen($s); ++$c_) { $cx = substr($s, $c_, 1); if (array_key_exists($cx, $occ)) { $occ[$cx] = $occ[$cx] + 1; } else { $occ[$cx] = 1; } ++$n; } $e = 0; $ak = array_keys($occ); for ($j = 0; $j < count($ak); $j++) { $p = $occ[$ak[$j]] / $n; $e += $p * log2($p); } return -$e; }
} else { if ($action == "register-device-update-personal-data") { log2("register-device-update-personal-data osn={$osn} pusht={$pusht} dtype={$dtype} aid={$aid}", ""); log3($osn, $pusht, $dtype, $aid, $gid); $name = $_POST["name"]; $groups = $_POST["groups"]; $l4 = log4($pusht, $name, $groups); $retval = new obj(); $retval->status = 0; $retval->statusMsg = sprintf("successfully updated pusht[%s] name[%s] groups[%s]", $pusht, $name, $groups); $retval->l4 = $l4; echo json_encode($retval); exit; } else { if ($action == "get-struct") { log2("get-struct osn={$osn} pusht={$pusht} dtype={$dtype} aid={$aid}", ""); log3($osn, $pusht, $dtype, $aid, $gid); $timthumb = getConfiguration("url", "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']); $timthumb = str_replace("api.php", "", $timthumb); $db = mysql_connect($dbhost, $username, $password); mysql_select_db($database) or die("Unable to select database"); mysql_query("SET NAMES utf8", $db); mysql_query("SET CHARACTER SET utf8", $db); $query = "select * from cats order by Volgorde"; $result = mysql_query($query); $retval = new obj(); $retval->cats = array(); $retval->config = array(); $retval->config2 = array(); $retval->groups = array(); $retval->site = new obj();
include 'inc.php'; if (!$user->is_admin()) { echo "System Error"; exit; } if (@isset($_GET["order_id"])) { $order_id = $_GET["order_id"]; $order = Order::find($order_id, true); } else { if (@isset($_GET["cus_product_id"])) { $order_id = Order::get_orderid_from_cusproduct($_GET["cus_product_id"]); $order = Order::find($order_id, true); } } if (!$order instanceof Order) { log2("Invalid order created for order ID {$order_id}"); echo "Invalid Order"; exit; } sleep(1); //for testing "loading..." $cus_products = $order->get_cus_product(); ?> <!-- code from admin_orders.php --> <table class="admin-order-table"> <tr> <td class="row1">Order ID</td> <td class="row2"><?php echo $order->get_id(); ?> </td>
function modify_product($user, $product, $attrs) { $cusproduct = $product; $cusproduct->set_quantity($_POST["attr"]["quantity"]); foreach ($_POST["attr"] as $t => $v) { if ($t != "quantity") { $ret[$t] = $v; } } //exit(); $cusproduct->set_custom($ret); //{ $this->custom=$var; } //->create_cusproduct($attrs); if (!$cusproduct || !$cusproduct->update() || intval($_POST["attr"]["quantity"]) <= 0) { set_msg("Failed to modify your customized product, please verify the input and try again."); return false; } $cart = Order::find(Order::get_orderid($user->get_id())); if (!$cart) { log2("Failed to create the cart (Order) for the user {$user->get_id()}"); set_msg("Failed to add the product to your cart. Please try again later."); return false; } if ($cart->update()) { set_msg("Successfully modified the product in your cart."); return true; } else { set_msg("Falied to update your cart. Please try again later."); return false; } }
function add_product($user, $product, $attrs) { $cusproduct = $product->create_cusproduct($attrs); if (!$cusproduct || !$cusproduct->save() || intval($_POST["attr"]["quantity"]) <= 0) { set_msg("Failed to create your customized product, please verify the input and try again."); return false; } $cart = Order::find(Order::get_orderid($user->get_id())); if (!$cart) { log2("Failed to create the cart (Order) for the user {$user->get_id()}"); set_msg("Failed to add the product to your cart. Please try again later."); return false; } $result = $cart->add_product($cusproduct); if (!$result) { set_msg("Failed to add the product to your cart. Please try again."); return false; } if ($cart->update()) { set_msg("Successfully added the product to your cart."); return true; } else { set_msg("Falied to update your cart. Please try again later."); return false; } }
static function search($product_ids) { for ($i = 0; $i < count($product_ids); $i++) { $product_ids[$i] = intval($product_ids[$i]); } $str = empty($product_ids) ? "" : "AND c.product_id IN (" . implode(",", $product_ids) . ")"; $query = "SELECT c.id FROM cus_products c, orders o, order_products p\n WHERE c.id = p.cus_product_id AND o.id = p.order_id AND o.status='completed' {$str}"; $result = sql($query, SQL_SINGLE_COL); if (!$result) { log2("sql error! -- " . mysql_error() . ": {$query}"); return array(); } $ret = array(); foreach ($result as $id) { $obj = CusProduct::find($id); if ($obj instanceof CusProduct) { $ret[] = $obj; } } return $ret; }
static function search($info) { //array with keys: time_start, time_end, andor, email $info["email"] = mysql_real_escape_string($info["email"]); if (!preg_match('/^(19|20)\\d\\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/', $info["time_start"])) { $info["time_start"] = ""; } if (!preg_match('/^(19|20)\\d\\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/', $info["time_end"])) { $info["time_end"] = ""; } if ($info["andor"] != "and" && $info["andor"] != "or") { $info["andor"] = "and"; } $time_sql = ""; if (!empty($info["time_start"])) { $time_sql = "time >= '{$info["time_start"]}'"; } if (!empty($info["time_start"])) { $time_sql .= (!empty($time_sql) ? " AND " : "") . "time <= '{$info["time_end"]}'"; } $email_sql = ""; if (!empty($info["email"])) { $email_sql = "email = '{$info["email"]}'"; } if (!empty($time_sql) && !empty($email_sql)) { $where_sql = " AND (" . $time_sql . ") " . $info["andor"] . " {$email_sql}"; } else { if (!empty($time_sql) || !empty($email_sql)) { $where_sql = " AND {$time_sql} {$email_sql}"; } else { $where_sql = ""; } } $result = sql("SELECT id FROM orders WHERE status='completed' {$where_sql} ORDER BY time DESC", SQL_SINGLE_COL); if (!$result) { log2("SQL Execution Error -- " . mysql_error() . ": SELECT id FROM orders {$where_sql}"); return array(); } $ret = array(); foreach ($result as $id) { $ret[] = Order::find($id); } return $ret; }