Пример #1
0
 /**
  * @constructor
  *
  * @param {array}  $rules Redirect rules
  * @param {callable|string} $rules[][source] Regex, plain string startsWith() or callback matcher func,
  * @param {string} $rules[][target] String for redirection, can use backreference on regex,
  * @param {?int}   $rules[][options] Redirection $options, or internal by default,
  * @param {?string} $options[source] Base path to match against requests, defaults to root.
  * @param {string|callable} $options[target] Redirects to a static target, or function($request) returns a string;
  */
 public function __construct($rules)
 {
     // rewrite all URLs
     if (is_string($rules)) {
         $rules = array('*' => $rules);
     }
     $rules = util::wrapAssoc($rules);
     $this->rules = array_reduce($rules, function ($result, $rule) {
         $rule = array_select($rule, array('source', 'target', 'options'));
         // note: make sure source is callback
         if (is_string($rule['source'])) {
             // regex
             if (@preg_match($rule['source'], null) !== false) {
                 $rule['source'] = matches($rule['source']);
                 if (is_string($rule['target'])) {
                     $rule['target'] = compose(invokes('uri', array('path')), replaces($rule['source'], $rule['target']));
                 }
             } else {
                 if (!is_callable($rule['source'])) {
                     $rule['source'] = startsWith($rule['source']);
                     if (is_string($rule['target'])) {
                         $rule['target'] = compose(invokes('uri', array('path')), replaces('/^' . preg_quote($rule['source']) . '/', $rule['target']));
                     }
                 }
             }
         }
         if (!is_callable($rule['source'])) {
             throw new InvalidArgumentException('Source must be string, regex or callable.');
         }
         $result[] = $rule;
         return $result;
     }, array());
 }
Пример #2
0
 public function __construct($options)
 {
     if (!empty($options['default'])) {
         if (is_string($options['default'])) {
             $locale = Locale::parseLocale($options['default']);
         }
         $locale = array_select($locale, ['language', 'region']);
         $this->defaultLocale = implode('_', $locale);
     }
 }
 public function find_all($constraints = array())
 {
     global $wpdb;
     $table = $this->table_name();
     $columns = implode(",\n  ", $this->table_columns);
     $where_constraints = array_select($constraints, $this->table_columns);
     $where = $this->mk_query_str($where_constraints);
     $limit = $this->mk_limit_clause($constraints);
     $query = str_reindent("\n      SELECT\n        {$columns}\n      FROM\n        {$table}\n      WHERE\n        {$where}\n      LIMIT {$limit};\n    ");
     $rows = $wpdb->get_results($query);
     return array_map(array($this, 'mk_entry'), $rows);
 }
Пример #4
0
 /**
  * @constructor
  */
 public function __construct($data = null)
 {
     if ($data instanceof Task) {
         // relation: Task
         $this->task($data);
         // Also stores the task identity "$name@$version"
         $this->identity = str_replace('@', '@~', $data->identity());
         $this->name = $data->name;
         $this->version = $data->version;
         $this->type = $data->extra['type'];
         $this->extra = array_select($data->extra, array('name', 'endpoint'));
         if (isset($data->settings)) {
             $this->settings = $data->settings;
         }
         // Copy fields from Task model
         $data = $data->data();
     } else {
         parent::__construct($data);
     }
 }
Пример #5
0
        $field['type_select'] = array_select('type', $type_arr, $field['type'], 0);
        $checkfield_arr = array(0 => 'Без проверки', 1 => 'Не пустое поле');
        if (!$field['checkfield'] && !$field['name']) {
            $field['checkfield'] = 1;
        }
        $field['checkfield_select'] = array_select('checkfield', $checkfield_arr, $field['checkfield'], 0);
        $field['ord_select'] = ord_select("SELECT name FROM " . TABLE_QUESTFIELD . " WHERE field_id!={$field_id} AND quest_id={$field['quest_id']} ORDER BY ord", 'ord', $field['ord']);
        $content = get_template('templ/field.htm', $field);
    }
    return;
}
if ($quest_id) {
    $sql = mysql_query("SELECT * FROM " . TABLE_QUESTIONNAIRE . " WHERE quest_id='{$quest_id}'") or Error(1, __FILE__, __LINE__);
    if ($quest = @mysql_fetch_array($sql)) {
        $quest['name'] = htmlspecialchars($quest['name'], ENT_COMPAT, 'cp1251');
        $quest['public_select'] = array_select('public', array(0 => 'Нет', 1 => 'Да'), $quest['public'], 0);
        $quest['butt'] = htmlspecialchars($quest['butt'], ENT_COMPAT, 'cp1251');
        if (!$quest['butt']) {
            $quest['butt'] = 'Отправить запрос';
        }
        $quest['email'] = htmlspecialchars($quest['email'], ENT_COMPAT, 'cp1251');
        $quest['objects'] = array();
        $sql1 = mysql_query("SELECT ob.country_id, ob.city_id, ob.object_id, ob.name, ct.name as city FROM " . TABLE_OBJECT . " ob \n\t\t\tLEFT JOIN " . TABLE_CITY . " ct ON (ct.city_id=ob.city_id)\n\t\t\tWHERE quest_id={$quest_id}  ORDER BY name") or Error(1, __FILE__, __LINE__);
        while ($field = @mysql_fetch_array($sql1)) {
            $field['name'] = htmlspecialchars($field['name'], ENT_COMPAT, 'cp1251');
            $field['city'] = htmlspecialchars($field['city'], ENT_COMPAT, 'cp1251');
            $field['link'] = "?p=catalogue&country_id={$field['country_id']}&city_id={$field['city_id']}&object_id={$field['object_id']}";
            $field['del_link'] = "?p=quest&delobj={$field['object_id']}&quest_id={$quest_id}";
            $quest['objects'][] = $field;
        }
        $content = get_template('templ/quest.htm', $quest);
Пример #6
0
    }
    $_SESSION['basket_data'] = serialize($arr);
    Header("Location: ?p={$part}");
    exit;
}
$data = @unserialize($_SESSION['basket_data']);
foreach ($basket_arr as $v) {
    ${$v} = @$data[$v];
}
$replace = array();
$replace['datesel'] = $datesel;
$sort = isset($sort_arr[$sort]) ? $sort : 'z.order_id';
$s = $sort == 'z.order_id' ? 'z.order_id + 0' : $sort;
$replace['sort_select'] = array_select('sort', $sort_arr, $sort);
$sortdirect = isset($sort_direct_arr[$sortdirect]) ? $sortdirect : 'desc';
$replace['sort_direct'] = array_select('sortdirect', $sort_direct_arr, $sortdirect);
$where = ' AND z.basket';
$where_date = $where;
$ord = "{$s} {$sortdirect}";
$d_field = $datesel == 2 ? 'annul_date' : ($datesel == 1 ? 'date_from' : 'date');
if ($mindate) {
    $where .= " AND z.{$d_field}>='{$mindate}'";
}
if ($maxdate) {
    $where .= " AND z.{$d_field}<='{$maxdate}'";
}
if (!$mindate || !$maxdate) {
    $sql = mysql_query("SELECT min({$d_field}) as mindate, max({$d_field}) as maxdate\n\tFROM \n\t\t" . TABLE_ORDER . " z \n\t\tLEFT JOIN " . TABLE_OFFICE . " r on (r.office_id=z.office_id) \n\tWHERE 1 {$where_date}") or Error(1, __FILE__, __LINE__);
    $arr = mysql_fetch_array($sql);
    if (!$mindate) {
        $mindate = @$arr['mindate'];
Пример #7
0
 /**
  * Upsert function.
  *
  * @param $table Target table name.
  * @param $data Key-value pairs of field names and values.
  *
  * @returns True on update succeed, insertId on a row inserted, false on failure.
  */
 public static function upsert($table, array $data, $update = null)
 {
     $fields = static::escapeField(array_keys($data), $table);
     $values = array_values($data);
     $query = sprintf('INSERT INTO %s (%s) VALUES (%s)', static::escapeField($table), implode(', ', $fields), implode(', ', array_fill(0, count($fields), '?')));
     // append "ON DUPLICATE KEY UPDATE ..."
     $keys = static::getFields($table, 'PRI');
     $fields = array_intersect($fields, static::escapeField($keys, $table));
     if ($fields) {
         // selective update
         if ($update !== null) {
             $data = array_select($data, (array) $update);
         }
         foreach ($data as $field => $value) {
             $data["`{$field}` = ?"] = $value;
             unset($data[$field]);
         }
         // full dataset appended with non-key fields
         $values = array_merge($values, array_values(array_filter_keys($data, notIn($keys))));
         $query .= ' ON DUPLICATE KEY UPDATE ';
         if ($data) {
             $query .= implode(', ', array_keys($data));
         } else {
             // note: key1 = key1; We do not use INSERT IGNORE because it'll ignore other errors.
             $value = reset($fields);
             $query .= "{$value} = {$value}";
             unset($value);
         }
     }
     unset($keys, $fields);
     $res = static::query($query, $values);
     unset($query, $values);
     if ($res !== false) {
         $res->closeCursor();
         // Inserted, return the new ID.
         if ($res->rowCount() == 1) {
             // Note: mysql_insert_id() doesn't do UNSIGNED ZEROFILL!
             $res = (int) static::getConnection()->lastInsertId();
             //$res = static::fetchField("SELECT MAX(ID) FROM `$table`;");
         } else {
             $res = true;
         }
     }
     return $res;
 }
Пример #8
0
// Log the process output if available
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
if ("{$stdout}{$stderr}") {
    $method = $stderr ? 'error' : 'info';
    Log::$method(sprintf('Output captured from command line: %s', $process['command']), array_filter(array('stdout' => $stdout, 'stderr' => $stderr)));
    unset($method);
}
unset($stdout, $stderr);
// Handles cleanup after process exit
switch (strtolower($process['type'])) {
    // Permanent processes will be restarted upon death
    case 'permanent':
        core\Database::query('UPDATE `' . FRAMEWORK_COLLECTION_PROCESS . '` SET `pid` = NULL WHERE `id` = ?', $process['id']);
        Log::debug('Permanent process died, clearing pid.', [$res, $process]);
        break;
        // Sets pid to 0, prevents it fire again and double enqueue of the same time slot.
    // Sets pid to 0, prevents it fire again and double enqueue of the same time slot.
    case 'cron':
        core\Database::query('UPDATE `' . FRAMEWORK_COLLECTION_PROCESS . '` SET `pid` = 0 WHERE `id` = ?', $process['id']);
        break;
        // Deletes the process object upon exit
    // Deletes the process object upon exit
    default:
        $process = array_select($process, array(Node::FIELD_COLLECTION, 'id', 'pid'));
        $res = Node::delete($process);
        Log::debug("Deleting finished process, affected rows: {$res}.", [$res, $process]);
        break;
}
// Recursive process, spawn another worker.
Process::spawnWorker(@$_SERVER['env']);
Пример #9
0
$where .= " AND !z.porder_id";
$sort = isset($sort_arr[$sort]) ? $sort : 'z.order_id';
$s = $sort == 'z.order_id' ? 'z.order_id + 0' : ($sort == 'z.tphone' ? 'z.tphone!=\'\'' : $sort);
$sortdirect = isset($sort_direct_arr[$sortdirect]) ? $sortdirect : 'desc';
$replace['sort'] = $sort;
$replace['sortdirect'] = $sortdirect;
$ord = "{$s} {$sortdirect}";
if ($sort == 'z.tphone') {
    $ord = "z.card_id>0 desc, z.card_id {$sortdirect}, z.order_id desc";
}
if ($sort == 'z.fio') {
    $ord = "if(z.fio!='',z.fio,clientname)!='' desc, if(z.fio!='',z.fio,clientname) {$sortdirect}";
}
$replace['card_vip'] = (int) $card_vip;
$replace['card_id'] = (int) $card_id;
$replace['card_vip_select'] = array_select('card_vip', array(0 => '', 1 => 'Vip'), $replace['card_vip']);
if ($card_id) {
    $where .= " AND z.card_id='{$card_id}' AND z.card_vip='{$card_vip}'";
}
if ($agency_id) {
    $where .= " AND z.agency_id='{$agency_id}'";
}
if ($corporate_id) {
    $where .= " AND z.corporate_id='{$corporate_id}'";
}
$replace['agency_select'] = mysql_select('agency_id', "SELECT agency_id, name FROM " . TABLE_AGENCY . " WHERE 1 ORDER BY name", $agency_id, 1, "style='width: 200px'", $agency_count);
$replace['corporate_select'] = mysql_select('corporate_id', "SELECT corporate_id, name FROM " . TABLE_CORPORATE . " WHERE 1 ORDER BY name", $corporate_id, 1, "style='width: 200px'", $corporate_count);
if (!@$year) {
    $sql = mysql_query("SELECT MAX(YEAR(z.date)) FROM {$tables} WHERE 1 {$where}") or Error(1, __FILE__, __LINE__);
    $arr = @mysql_fetch_array($sql);
    $year = @$arr[0] ? (int) $arr[0] : 'all';
Пример #10
0
}
$replace['mindate'] = $mindate ? sql_to_text_date($mindate, 0, 1) : '';
$replace['maxdate'] = $maxdate ? sql_to_text_date($maxdate, 0, 1) : '';
$sort = isset($sort_arr[$sort]) ? $sort : 'procent';
if ($sort == 'username' && $type == 1) {
    $sort = 'objectname';
}
if ($sort == 'objectname' && $type == 0) {
    $sort = 'username';
}
$replace['sort'] = $sort;
$sortdirect = isset($sort_direct_arr[$sortdirect]) ? $sortdirect : 'desc';
$replace['sortdirect'] = $sortdirect;
$s = $sort;
$ord = "{$sort} {$sortdirect}";
$replace['type_select'] = array_select('type', $type_arr, $type);
if ($type == 0) {
    $users = array();
    //$discount_fields = "if( z.discount, if(z.inall, z.discount *100 / z.inall, 0), z.skidka ) as procent, z.inall-z.netto as vrubl ";
    $sql = mysql_query("\n\t\tSELECT \n\t\t\tu.user_id, u.name as username,\n\t\t\tavg(z.skidka) as procent\n\t\tFROM \n\t\t\t" . TABLE_USER . " u\n\t\t\tLEFT JOIN " . TABLE_ORDER . " z ON (z.user_id=u.user_id)\n\t\t\tLEFT JOIN " . TABLE_OBJECT . " ob  on (ob.object_id=z.object_id) \n\t\t\tLEFT JOIN " . TABLE_CITY . " ct ON (ob.city_id=ct.city_id)\n\t\tWHERE \n\t\t\tu.active AND z.skidka AND {$where}\n\t\tGROUP BY\n\t\t\tu.user_id\n\t\tORDER BY \n\t\t\t{$ord} ") or Error(1, __FILE__, __LINE__);
    $users = array();
    $i = ($current_page - 1) * $_SESSION['on_page'];
    $j = 0;
    while ($info = @mysql_fetch_array($sql)) {
        $i++;
        $j++;
        $info['i'] = $i;
        $info['j'] = $j;
        $info['procent'] = number_format($info['procent'], 1);
        $users[] = $info;
    }
Пример #11
0
Файл: pay.php Проект: nikuha/rs
}
if ($mindate) {
    $where .= " AND z.{$d_field}>='{$mindate}'";
}
if ($maxdate) {
    $where .= " AND z.{$d_field}<='{$maxdate}'";
}
$replace['mindate'] = $mindate ? sql_to_text_date($mindate, 0, 1) : '';
$replace['maxdate'] = $maxdate ? sql_to_text_date($maxdate, 0, 1) : '';
$sort = isset($sort_arr[$sort]) ? $sort : 'z.order_id';
$s = $sort == 'z.order_id' ? 'z.order_id + 0' : $sort;
$sortdirect = isset($sort_direct_arr[$sortdirect]) ? $sortdirect : 'asc';
$replace['sort'] = $sort;
$replace['sortdirect'] = $sortdirect;
$payment_arr = array(0 => 'неоплаченные клиентом', 1 => 'частичная оплата клиентом', 2 => 'неоплачено поставщику', 3 => 'неоплаченный долг поставщика', 4 => 'дополнительные платежи');
$replace['payment_select'] = array_select('payment', $payment_arr, $payment);
if ($payment == 4) {
    $where .= " AND i.inventory_id";
    $sum_field = 'i.summa';
} elseif ($payment == 3) {
    $where .= " AND z.debt>0 AND !z.paid_debt";
    $sum_field = 'z.debt';
} elseif ($payment == 2) {
    $where .= " AND !z.paytoprovider AND !z.paid_provider AND (z.paid OR z.prepaid)";
    $sum_field = 'z.provider_sum';
} elseif ($payment == 1) {
    $where .= " AND (!z.paid AND z.prepaid AND z.inall>z.prepayment) AND !z.nameste";
    $sum_field = 'z.inall-z.prepayment';
} else {
    $where .= " AND !z.paid AND !z.prepaid";
    $sum_field = 'z.inall';
Пример #12
0
    }
    $error = '';
    if (empty($expected) || expect_equal($expected, $result, $title, $error)) {
        $n_pass++;
    } else {
        $n_fail++;
        echo "{$error}\n";
    }
    return $result;
}
if ($test_verbose) {
    echo "test set partial margins:\n";
}
# Baseline - auto calculated margins:
$base = test("SetMarginPixels baseline", False, 0x0, False, 0x0, True);
# Cases of SetMarginsPixels:
for ($mask = 0; $mask < 16; $mask++) {
    test("SetMarginPixels {$mask}", True, $mask, False, 0, True, array_select($margins_override, $base, $mask, 4));
}
# Baseline - for plot area:
$base = test("SetPlotAreaPixels baseline", False, 0x0, False, 0x0, False);
# Cases of SetPlotAreaPixels:
for ($mask = 0; $mask < 16; $mask++) {
    test("SetPlotAreaPixels {$mask}", False, 0, True, $mask, False, array_select($plotarea_override, $base, $mask, 4));
}
# ======== End of test cases and error reporting ==========
echo "test set partial margins: {$n_tests} test cases, {$n_pass} pass, {$n_fail} fail\n";
if ($n_fail > 0) {
    exit(1);
}
# PHPlot test suite requires falling off the end, not exit, on success.
Пример #13
0
  function Render()
  {
    global $currentUser;

    if (!$currentUser)
      return;

    if (!$currentUser->CanSubmitItems())
      return;

    echo "\n\n";
    echo "<div class='pouettbl' id='".$this->uniqueID."'>\n";

    echo "  <h2>".$this->title."</h2>\n";
    $fields = array_select($this->fields,array("name"));
    if ($fields)
    {
      echo "  <div class='content'>\n";
      $this->formifier->RenderForm( $fields );
      echo "  </div>\n";
    }

    $fields = array_select($this->fields,array("group1","group2","group3"));
    if ($fields)
    {
      echo "  <h2 id='groups'>groups</h2>\n";
      echo "  <div class='content'>\n";
      $this->formifier->RenderForm( $fields );
      echo "  </div>\n";
    }

    $fields = array_select($this->fields,array("download","releaseDate","platform","type"));
    if ($fields)
    {
      echo "  <h2 id='basicinfo'>basic info</h2>\n";
      echo "  <div class='content'>\n";
      $this->formifier->RenderForm( $fields );
      echo "  </div>\n";
    }

    $fields = array_select($this->fields,array("partyID","partyYear","partyCompo","partyRank","invitationParty","invitationYear"));
    if ($fields)
    {
      echo "  <h2 id='partyinfo'>party info</h2>\n";
      echo "  <div class='content'>\n";
      $this->formifier->RenderForm( $fields );
      echo "  </div>\n";
    }

    $fields = array_select($this->fields,array("csdbID","demozooID","boardID"));
    if ($fields)
    {
      echo "  <h2 id='othersites'>other sites</h2>\n";
      echo "  <div class='content'>\n";
      $this->formifier->RenderForm( $fields );
      echo "  </div>\n";
    }

    $fields = array_select($this->fields,array("nfofile","screenshot"));
    if ($fields)
    {
      echo "  <h2 id='files'>files</h2>\n";
      echo "  <div class='content'>\n";
      $this->formifier->RenderForm( $fields );
      echo "  </div>\n";
    }

    echo "  <div class='foot'><input type='submit' value='Submit' /></div>";
    echo "</div>\n";
  }
Пример #14
0
	$extra_table_cond = 'z.agency_id=c.agency_id';
	$extra_fields = '';

	if($mindate) $extra_table_cond .= " AND z.date>='$mindate'";
	if($maxdate) $extra_table_cond .= " AND z.date<='$maxdate'";
	$replace['mindate'] = $mindate ? sql_to_text_date($mindate, 0, 1) : '';
	$replace['maxdate'] = $maxdate ? sql_to_text_date($maxdate, 0, 1) : '';	
	
	if($mindate || $maxdate)
	{
		$extra_table .= "LEFT JOIN ".TABLE_ORDER." z ON (z.status=1 AND $extra_table_cond)";	
		$where .= " AND z.order_id";
		$extra_fields .= ", count(z.order_id) as o_count, SUM(z.inall) as o_summa";
	}
	
	$replace['status_select'] = array_select('status', $agency_type, $status, 1);
	if($status) $where .= " AND c.status='$status'";

		
	$sql = mysql_query("SELECT count(*) FROM ".TABLE_AGENCY." c $extra_table WHERE $where") or Error(1, __FILE__, __LINE__);
	$arr = mysql_fetch_array($sql);
	$replace['all'] = $all = $arr[0];
		
	list($limit, $replace['pages']) = pages($all, ADMIN_URL."?p=$part&");
	
	$sql = mysql_query("SELECT c.* $extra_fields FROM ".TABLE_AGENCY." c
		$extra_table
		WHERE $where  
		GROUP BY c.agency_id
		ORDER BY $ord LIMIT $limit") 
		or Error(1, __FILE__, __LINE__);
Пример #15
0
 $extra_table_cond = 'z.corporate_id=c.corporate_id';
 $extra_fields = '';
 if ($mindate) {
     $extra_table_cond .= " AND z.date>='{$mindate}'";
 }
 if ($maxdate) {
     $extra_table_cond .= " AND z.date<='{$maxdate}'";
 }
 $replace['mindate'] = $mindate ? sql_to_text_date($mindate, 0, 1) : '';
 $replace['maxdate'] = $maxdate ? sql_to_text_date($maxdate, 0, 1) : '';
 if ($mindate || $maxdate) {
     $extra_table .= "LEFT JOIN " . TABLE_ORDER . " z ON (z.status=1 AND {$extra_table_cond})";
     $where .= " AND z.order_id";
     $extra_fields .= ", count(z.order_id) as o_count, SUM(z.inall) as o_summa";
 }
 $replace['status_select'] = array_select('status', $corporate_type, $status, 1);
 if ($status) {
     $where .= " AND c.status='{$status}'";
 }
 $sql = mysql_query("SELECT count(*) FROM " . TABLE_CORPORATE . " c {$extra_table} WHERE {$where}") or Error(1, __FILE__, __LINE__);
 $arr = mysql_fetch_array($sql);
 $replace['all'] = $all = $arr[0];
 list($limit, $replace['pages']) = pages($all, ADMIN_URL . "?p={$part}&");
 $sql = mysql_query("SELECT c.* {$extra_fields} FROM " . TABLE_CORPORATE . " c\n\t\t{$extra_table}\n\t\tWHERE {$where}  \n\t\tGROUP BY c.corporate_id\n\t\tORDER BY {$ord} LIMIT {$limit}") or Error(1, __FILE__, __LINE__);
 $corporates = array();
 $corporate_name = "";
 while ($info = @mysql_fetch_array($sql)) {
     $info['name'] = htmlspecialchars($info['name'], ENT_COMPAT, 'cp1251');
     $info['o_count'] = (int) @$info['o_count'];
     $info['o_summa'] = (int) @$info['o_summa'];
     $info['order_link'] = "?p={$part}&searchorder=1&corporate_id={$info['corporate_id']}";
Пример #16
0
Файл: user.php Проект: nikuha/rs
 }
 $info['order_box'] = $order_box;
 $info['attention_box'] = $attention_box;
 $info['account_box'] = $account_box;
 $info['message_box'] = $message_box;
 $info['support_box'] = $support_box;
 $info['arrival_box'] = $arrival_box;
 $info['inventory_box'] = $inventory_box;
 $info['user'] = array_select('user', array(0 => 'Нет', 1 => 'Да'), $info['user']);
 foreach ($danet_arr as $v) {
     $n = $v == 'quest' ? 'quest1' : $v;
     $info[$v] = array_select($n, array(0 => 'Нет', 1 => 'Да'), $info[$v]);
 }
 $info['siteorder'] = array_select('siteorder', array(0 => 'Только свои', 1 => 'Просмотр всех', 2 => 'Администратор'), $info['siteorder']);
 $info['card'] = array_select('card', array(0 => 'Нет', 1 => 'Выдача vip-карт', 2 => 'Все карты'), $info['card']);
 $info['active'] = array_select('active', array(0 => 'Нет', 1 => 'Да'), $info['active']);
 $info['users_link'] = ADMIN_URL . "?p={$part}";
 $info['objectlist'] = $info['objects'];
 $object_list = array();
 if ($info['objects']) {
     $arr = explode(',', $info['objects']);
     foreach ($arr as $k => $v) {
         $arr[$k] = "ob.object_id=" . (int) $v;
     }
     $where_obj = join(' OR ', $arr);
     $sql_obj = mysql_query("SELECT object_id, name FROM " . TABLE_OBJECT . " ob WHERE {$where_obj} ORDER BY name") or Error(1, __FILE__, __LINE__);
     while ($object = @mysql_fetch_array($sql_obj)) {
         $object_list[] = htmlspecialchars($object['name'], ENT_COMPAT, 'cp1251');
     }
 }
 $info['object_list'] = join('<br>', $object_list);
Пример #17
0
 /**
  * (read-only) Create fingerprint from the info available in HTTP request.
  *
  * note: The algorithm is supposed to change from time to time.
  *
  * @return {string} Fingerprint hash from current request, or null when no such info is available.
  */
 public function fingerprint()
 {
     $fingerprint = $this->meta('fingerprint');
     if ($fingerprint) {
         return $fingerprint;
     }
     $fingerprint = array_select($this->client, array('address', 'userAgent'));
     $fingerprint = array_filter($fingerprint);
     $fingerprint = implode(':', $fingerprint);
     if ($fingerprint) {
         return sha1($fingerprint);
     }
 }
Пример #18
0
 function array_filter_keys($list, $func)
 {
     return array_select($list, array_filter(array_keys($list), $func));
 }
Пример #19
0
    }
}
if (!$client_id) {
    $client = array();
    $client['birthday'] = '';
    $client['birthday_city'] = '';
    $client['name'] = '';
    $client['pasport'] = '';
    $client['text'] = '';
    $client['sex'] = '';
    $client['email'] = '';
    $client['phone'] = '';
    $client['vip'] = 0;
    $client['card_id'] = '';
    $client['city_id'] = 0;
    $client['vip_select'] = array_select('vip', array(0 => '', 1 => 'Vip'), $client['vip']);
    $client['order_list'] = array();
}
if ($order_id) {
    $sql = mysql_query("SELECT z.email, z.porder_id FROM " . TABLE_ORDER . " z  WHERE z.order_id='{$order_id}' ") or Error(1, __FILE__, __LINE__);
    $arr = mysql_fetch_array($sql);
    if (!$arr['email'] && $client['email'] && !$arr['porder_id']) {
        $orderemail = $client['email'];
    } else {
        $orderemail = '';
    }
} elseif ($client_id) {
    $arr = @unserialize($_SESSION['form_data']);
    if (!@$arr['email']) {
        $sql = mysql_query("SELECT email FROM " . TABLE_CLIENT . "  WHERE client_id='{$client_id}' ") or Error(1, __FILE__, __LINE__);
        $arr1 = @mysql_fetch_array($sql);
Пример #20
0
Файл: card.php Проект: nikuha/rs
            $replace['card_list_vip'] = $card_list;
        } else {
            $replace['card_list'] = $card_list;
        }
    }
    $content = get_template('templ/cardid.htm', $replace);
    return;
}
if ($card_id) {
    $vip = (int) @$vip;
    $sql = mysql_query("SELECT * FROM " . TABLE_CARD . " WHERE card_id='{$card_id}' AND vip='{$vip}' AND active!=0") or Error(1, __FILE__, __LINE__);
    if ($card = @mysql_fetch_array($sql)) {
        foreach ($contact_arr as $v) {
            $card[$v] = htmlspecialchars($card[$v], ENT_COMPAT, 'cp1251');
        }
        $card['active_select'] = array_select('active', array(-1 => 'Заблокирована', 1 => 'Активна'), $card['active'], 0, "onchange=\"blockdiv.style.display = (this.value==-1) ? '' : 'none'\"");
        $sql = mysql_query("SELECT count(*) FROM " . TABLE_ORDER . " WHERE card_id='{$card_id}' AND card_vip='{$vip}' AND !basket") or Error(1, __FILE__, __LINE__);
        $arr = @mysql_fetch_array($sql);
        $card['order_count'] = (int) @$arr[0];
        $card['order_link'] = "?p={$part}&searchorder=1&card_id={$card_id}&vip={$vip}";
        $sql = mysql_query("SELECT count(*) FROM " . TABLE_ORDER . " WHERE card_id='{$card_id}' AND card_vip='{$vip}' AND annul='' AND !basket") or Error(1, __FILE__, __LINE__);
        $arr = @mysql_fetch_array($sql);
        $card['active_count'] = (int) @$arr[0];
        $card['discount'] = get_discount($card['active_count'] + 1, $vip);
        $ofcount = 0;
        $card['office_select'] = mysql_select('office_id', "SELECT office_id, region FROM " . TABLE_OFFICE . " ORDER BY office_id", $card['office_id'], 0, '', $ofcount);
        $sql = mysql_query("SELECT MIN(card_id) FROM " . TABLE_CARD . " WHERE vip=1 AND active=0") or Error(1, __FILE__, __LINE__);
        $arr = @mysql_fetch_array($sql);
        $card['newcard_id'] = (int) @$arr[0];
        $card['admin_cardid'] = $admin_config['cardid'];
        $card['files'] = get_file_info($file_owner, $card['card_id']);
Пример #21
0
            $event['date'] = $date;
            $event['sy'] = $sy;
            $event['sm'] = $sm;
            if ($event['edit']) {
                $tinymce_elements = 'description';
                $tinymce_head = get_template('templ/tinymce_head.htm', array('tinymce_elements' => $tinymce_elements));
                $event['description'] = htmlspecialchars($event['description'], ENT_COMPAT, 'cp1251');
            }
            $event['type_select'] = array_select('type', array(0 => 'нет', 1 => 'добавленная заявка', 2 => 'текущая заявка', 3 => 'новость'), $event['type'], 0);
            if ($event['o_id']) {
                if ($event['type'] == 1) {
                    $event['o_link'] = "?p=order&order_id={$event['o_id']}";
                } elseif ($event['type'] == 2) {
                    $event['o_link'] = "?p=siteorder&siteorder_id={$event['o_id']}";
                } elseif ($event['type'] == 3) {
                    $event['o_link'] = "?p=innernews&news_id={$event['o_id']}";
                }
            } else {
                $event['o_link'] = '';
            }
            $event['status_select'] = array_select('status', array(0 => 'активно', 1 => 'выполнено'), $event['status'], 0);
        } else {
            if (!$event['description'] && $event['type'] == 3) {
                $sql = mysql_query("SELECT description FROM " . TABLE_NEWS . " WHERE news_id='{$event['o_id']}'") or Error(1, __FILE__, __LINE__);
            }
            $arr = @mysql_fetch_array($sql);
            $event['description'] = $arr['description'];
        }
        $content = get_template('templ/event.htm', $event);
    }
}
Пример #22
0
 /**
  * Put the specified command into process queue, optionally spawn a daemon to run it.
  *
  * @param {string} $command Command line to be run by the daemon.
  *
  * @param {array} $options Array with the following properties:
  *                $options[$spawn] {bool} Whether to spawn a worker daemon immediately, default true.
  *                $options[$singleton] {bool} Whether to skip the queuing when there is already an exact same command
  *                                           in the process list, default false.
  *                $options[$requeue] {bool} True to remove any previous inactive identical commands before pushing into
  *                                         queue, default false.
  *                $options[$kill] {int} When provided, a signal to be sent to all active identical commands.
  *                $options[$type] {string} Identifier of command queue groups, commands will be drawn and run randomly
  *                                        among groups, one at a time, by the daemon.
  *                $options[$weight] {int} The likeliness of a command to be drawn within the same group, default 1.
  *                $options[$capacity] {float} Percentage of occupation within the same group. To limit maximum active
  *                                           processes within the same group to be 10, set this to 0.1. Default 0.2.
  *                $options[$env] {array} Associative array of properties that will be available when target command starts.
  *                $options[...] Any other values will be set into the process object, which will be accessible by spawn
  *                              processes with Process::get() method.
  */
 public static function enqueue($command, $options = array())
 {
     // For backward-compatibility, this parameter is originally $spawnProcess.
     if (is_bool($options)) {
         $options = array('$spawn' => $options);
     } else {
         $options = (array) $options;
     }
     $options = array_filter($options, compose('not', 'is_null'));
     $options += self::$defaultOptions;
     $process = array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS, 'command' => $command) + array_select($options, array_filter(array_keys($options), compose('not', startsWith('$'))));
     // Remove identical inactive commands
     if ($options['$requeue']) {
         Node::delete(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS, 'command' => $command, 'pid' => null));
     }
     // Sends the specified signal to all active identical commands
     if (is_int(@$options['$kill'])) {
         if (!function_exists('posix_kill')) {
             throw new ProcessException('Platform does not support posix_kill command.', ERR_SUPRT);
         }
         $activeProcesses = Node::get(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS, 'command' => $command, 'pid' => '!=null'));
         foreach ($activeProcesses as $process) {
             posix_kill($process['pid'], $options['$kill']);
         }
         unset($activeProcesses);
     }
     // Only pushes the command into queue when there are no identical process.
     if ($options['$singleton']) {
         $identicalProcesses = Node::get(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS, 'command' => $command));
         // Process object will be updated
         if ($identicalProcesses) {
             $process['id'] = $identicalProcesses[0]['id'];
         }
         unset($identicalProcesses);
     }
     // Copy process related fields.
     foreach (['type', 'weight', 'capacity'] as $field) {
         if (isset($options["\${$field}"])) {
             $process[$field] = $options["\${$field}"];
         }
     }
     // Default start time to now
     if (empty($process['start_time']) || !strtotime($process['start_time'])) {
         $process['start_time'] = date('c');
     }
     // Push or updates target process.
     $res = Node::set($process);
     if ($res === false) {
         throw new ProcessException('Unable to enqueue process.', self::ERR_ENQUE);
     }
     if (is_numeric($res)) {
         $process['id'] = $res;
     }
     unset($res);
     $env = (array) @$options['$env'];
     if ($env) {
         $env = array('env' => ContentEncoder::json($env));
     }
     unset($options['$env']);
     // Only spawn a worker if target process is not already working.
     if (@$options['$spawn'] && !@$process['pid'] && !self::spawnWorker($env)) {
         throw new ProcessException('Unable to spawn daemon worker.', self::ERR_SPAWN);
     }
     return $process;
 }
Пример #23
0
Файл: tz.php Проект: nikuha/rs
$type_list = array();
foreach ($tztype_list as $k => $v) {
    $sql1 = mysql_query("SELECT count(*) FROM " . TABLE_TZ . "  WHERE type={$k}") or Error(1, __FILE__, __LINE__);
    $info = @mysql_fetch_array($sql1);
    $type_list[$k] = array('name' => $v, 'count' => (int) @$info[0]);
}
$replace['tztype_list'] = $type_list;
if ($tz_id) {
    $sql1 = mysql_query("SELECT * FROM " . TABLE_TZ . "  WHERE tz_id={$tz_id}") or Error(1, __FILE__, __LINE__);
    if (!($info = @mysql_fetch_array($sql1))) {
        $content = 'Не найдено задание!';
        return;
    }
    $info['name'] = htmlspecialchars($info['name'], ENT_COMPAT, 'cp1251');
    $info['description'] = htmlspecialchars($info['description'], ENT_COMPAT, 'cp1251');
    $info['type_select'] = array_select('type', $tztype_list, $info['type'], 0, "");
    $info['ord_select'] = ord_select("SELECT name FROM " . TABLE_TZ . " WHERE tz_id!={$tz_id} AND type={$info['type']} ORDER BY ord", 'ord', $info['ord']);
    $where = "g.news_id={$tz_id} AND g.type={$commenttype}";
    $sql = mysql_query("SELECT COUNT(*) FROM " . TABLE_OPINION . " g WHERE {$where}") or Error(1, __FILE__, __LINE__);
    $arr1 = mysql_fetch_array($sql);
    $info['all'] = $all = $arr1[0];
    list($limit, $pages) = pages($all, $url . "&");
    $opinion_list = array();
    $sql = mysql_query("\n\t\tSELECT \n\t\t\tg.* , u.name as uname\n\t\tFROM \n\t\t\t" . TABLE_OPINION . " g \n\t\t\tLEFT JOIN " . TABLE_USER . " u ON (u.user_id=g.user_id)\n\t\tWHERE\n\t\t\t{$where}\n\t\tORDER BY \n\t\t\tg.datetime, g.opinion_id \n\t\tLIMIT {$limit}") or Error(1, __FILE__, __LINE__);
    while ($arr1 = @mysql_fetch_array($sql)) {
        $arr1['uname'] = HtmlSpecialChars($arr1['uname'], ENT_COMPAT, 'cp1251');
        $arr1['text'] = comment_text($arr1['text']);
        list($date, $time) = explode(" ", $arr1['datetime']);
        $arr1['datetime'] = sql_to_text_date($date) . " " . substr($time, 0, 5);
        $arr1['del_link'] = $url . "&delopinion={$arr1['opinion_id']}";
        $opinion_list[] = $arr1;
Пример #24
0
 /**
  * @expectedException Exception
  * @expectedExceptionMessage Illegal $from type
  */
 public function testSelectFromNotArray()
 {
     $from = 'ololo';
     $expected = false;
     $this->assertEquals($expected, array_select('d', $from));
 }
Пример #25
0
function calendar($year, $month, $templ_file, $link, $public, $table = '', $type = 0)
{
    global $rus_month, $part, $admin_config;
    if (!$table) {
        $table = TABLE_NEWS;
    }
    if (!checkdate($month, 1, $year)) {
        $year = date("Y");
        $month = date("m");
    }
    $where = $type == -1 ? '1' : "type={$type}";
    if ($public) {
        $where .= " and public='1'";
    }
    if ($type == -1) {
        $where .= " AND (user_id={$_SESSION['admin_id']} OR public)";
    }
    $sql = mysql_query("SELECT YEAR(date) FROM " . $table . " WHERE {$where} ORDER BY YEAR(date) LIMIT 1") or Error(1, __FILE__, __LINE__);
    $info = @mysql_fetch_array($sql);
    $y_first = (int) @$info[0];
    // сегодня
    $yt = date("Y");
    $mt = date("m");
    $dt = date("j");
    $sql = mysql_query("SELECT count(*) FROM " . $table . " WHERE {$where} AND date=CURDATE() ") or Error(1, __FILE__, __LINE__);
    $today_link = '';
    if ($info = @mysql_fetch_array($sql)) {
        if ($info[0]) {
            $today_link = $public ? $link . "{$yt}/{$mt}/{$dt}/" : $link . "&date={$yt}-{$mt}-{$dt}";
        }
    }
    $sql = mysql_query("SELECT date, count(*) as count FROM " . $table . " WHERE {$where} AND YEAR(date)='{$year}' AND MONTH(date)='{$month}' GROUP BY date") or Error(1, __FILE__, __LINE__);
    $date_count = array();
    while ($info = @mysql_fetch_array($sql)) {
        $date_count[$info['date']] = $info['count'];
    }
    for ($dim = 31; $dim > 0; $dim--) {
        if (checkdate($month, $dim, $year)) {
            break;
        }
    }
    $dow1 = date("w", mktime(0, 0, 0, $month, 1, $year));
    if (!$dow1) {
        $dow1 = 7;
    }
    $dim -= 7 - $dow1 + 1;
    $wim = $dim % 7 ? (int) ($dim / 7) + 1 : ($wim = $dim / 7);
    $wim++;
    $week = array();
    $day = 0;
    $yt = date("Y");
    $mt = date("m");
    $dt = date("j");
    for ($i = 1; $i <= $wim; $i++) {
        $days = array();
        for ($dow = 1; $dow <= 7; $dow++) {
            $day_current = 0;
            $date = '';
            $today = 0;
            if ($day || !$day && $dow1 == $dow) {
                $day++;
                if (checkdate($month, $day, $year)) {
                    $date = sprintf("%04d-%02d-%02d", $year, $month, $day);
                    if (!@$date_count[$date]) {
                        $date = '';
                    }
                    if ($day == $dt && $month == $mt && $year == $yt) {
                        $today = 1;
                    }
                    $day_current = $day;
                }
            }
            if ($date) {
                $date_link = $public ? $link . "{$year}/{$month}/{$day}/" : $link . "&date={$date}";
            } else {
                $date_link = '';
            }
            $days[] = array('day' => $day_current, 'date_link' => $date_link, 'dow' => $dow, 'today' => $today);
        }
        # for days of week
        $week[] = array('days' => $days, 'i' => $i);
    }
    # for $week
    $arr_month = array();
    foreach ($rus_month as $k => $v) {
        if ($k) {
            $arr_month[$k] = $v;
        }
    }
    $replace = array();
    $replace['today_link'] = $today_link;
    $replace['year'] = $year;
    $replace['year_prev'] = "/{$part}/" . ($year - 1) . "/12/";
    $replace['year_next'] = "/{$part}/" . ($year + 1) . "/1/";
    $replace['month'] = @$rus_month[(int) $month];
    $month_prev = mktime(0, 0, 0, $month - 1, 1, $year);
    $replace['month_prev'] = "/{$part}/" . date("Y", $month_prev) . "/" . date("m", $month_prev) . "/";
    $month_next = mktime(0, 0, 0, $month + 1, 1, $year);
    $replace['month_next'] = "/{$part}/" . date("Y", $month_next) . "/" . date("m", $month_next) . "/";
    $replace['month_link'] = "/{$part}/{$year}/{$month}/";
    $replace['week'] = $week;
    $s = $year - 1 > $y_first ? $y_first : $year - 1;
    $e = $year + 1 < $yt ? $yt : $year + 1;
    $replace['select_year'] = digit_select('sy', $s, $e, $year);
    $replace['select_month'] = array_select('sm', $arr_month, $month);
    $replace['part'] = $part;
    return get_template($templ_file, $replace);
}
Пример #26
0
Файл: func.php Проект: nikuha/rs
function get_ticket_select($fname, $tour_id, $order_id, $carriage, $back, $tour_all_tcount)
{
	
	$sql = mysql_query("SELECT tcount FROM ".TABLE_TICKET."  WHERE order_id='$order_id' AND tour_id=$tour_id AND carriage=$carriage AND back=$back") 
		or Error(1, __FILE__, __LINE__);
	$arr = @mysql_fetch_array($sql);
	$order_tcount = (int)@$arr['tcount'];
	
	$sql = mysql_query("SELECT sum(tcount) FROM ".TABLE_TICKET."  WHERE tour_id=$tour_id AND carriage=$carriage AND back=$back") 
		or Error(1, __FILE__, __LINE__);
	$arr = @mysql_fetch_array($sql);
	$tour_tcount = $arr[0];
		
	$arr_p = array();
	for($i=0;$i<=$tour_all_tcount-($tour_tcount-$order_tcount);$i++) $arr_p[$i] = $i;
	$select = array_select($fname, $arr_p, $order_tcount);
	
	return array($select,$i);
}
Пример #27
0
}
$replace['forms'] = $forms;
$replace['field_id'] = $field_id;
$replace['form_id'] = $form_id;
$left_menu = get_template('templ/field_list.htm', $replace);
if ($field_id) {
    $sql = mysql_query("SELECT * FROM " . TABLE_QUESTFIELD . " WHERE field_id='{$field_id}'") or Error(1, __FILE__, __LINE__);
    if ($field = @mysql_fetch_array($sql)) {
        $field['name'] = htmlspecialchars($field['name'], ENT_COMPAT, 'cp1251');
        $field['data'] = htmlspecialchars($field['data'], ENT_COMPAT, 'cp1251');
        $field['public_select'] = array_select('public', array(0 => 'Нет', 1 => 'Да'), $field['public'], 0);
        $field['line_select'] = array_select('line', array(0 => 'Нет', 1 => 'Да'), $field['line'], 0);
        $type_arr = array(0 => 'Строка', 1 => 'Многострочный текст', 2 => 'Выбор из списка', 3 => 'Дата', 4 => 'Checkbox (галочки)', 5 => 'Адресат');
        $field['type_select'] = array_select('type', $type_arr, $field['type'], 0);
        $checkfield_arr = array(0 => 'Без проверки', 1 => 'Не пустое поле', 2 => 'Целое число', 3 => 'E-Mail', 4 => 'Дата');
        $field['checkfield_select'] = array_select('checkfield', $checkfield_arr, $field['checkfield'], 0);
        $field['ord_select'] = ord_select("SELECT name FROM " . TABLE_QUESTFIELD . " WHERE field_id!={$field_id} AND form_id={$field['form_id']} ORDER BY ord", 'ord', $field['ord']);
        $content = get_template('templ/field.htm', $field);
    }
    return;
}
if ($form_id) {
    $sql = mysql_query("SELECT * FROM " . TABLE_QUESTIONNAIRE . " WHERE form_id='{$form_id}'") or Error(1, __FILE__, __LINE__);
    if ($form = @mysql_fetch_array($sql)) {
        $form['name'] = htmlspecialchars($form['name'], ENT_COMPAT, 'cp1251');
        $form['butt'] = htmlspecialchars($form['butt'], ENT_COMPAT, 'cp1251');
        if (!$form['butt']) {
            $form['butt'] = 'Отправить запрос';
        }
        $form['email'] = htmlspecialchars($form['email'], ENT_COMPAT, 'cp1251');
        $content = get_template('templ/form.htm', $form);
Пример #28
0
}
if ($mindate) {
    $where .= " AND z.{$d_field}>='{$mindate}'";
}
if ($maxdate) {
    $where .= " AND z.{$d_field}<='{$maxdate}'";
}
$replace['mindate'] = $mindate ? sql_to_text_date($mindate, 0, 1) : '';
$replace['maxdate'] = $maxdate ? sql_to_text_date($maxdate, 0, 1) : '';
$age_sel = array();
foreach ($age_arr as $k => $age) {
    $age_sel[$k] = $age[2];
}
$replace['age_select'] = array_select('age_k', $age_sel, $age_k);
$replace['age_name'] = @$age_sel[$age_k];
$replace['sex_select'] = array_select('sex', array(0 => '', 1 => 'мужчины', 2 => 'женщины'), $sex);
$replace['sex_name'] = $sex == 1 ? 'мужчины' : ($sex == 2 ? 'женщины' : '');
$age_field = "( YEAR(CURRENT_DATE) - YEAR(cl.birthday) ) - ( DATE_FORMAT(CURRENT_DATE, '%m%d') < DATE_FORMAT(cl.birthday, '%m%d') )";
$client_arr = array();
if ($reverse) {
    $object_mega_arr = array();
    $client_object_arr = array();
}
$sql = mysql_query("\n\tSELECT \n\t\tz.clients, z.object_id, ob.name as object, ct.name as city\n\tFROM \n\t\t" . TABLE_ORDER . " z \n\t\tLEFT JOIN " . TABLE_OBJECT . " ob  on (ob.object_id=z.object_id) \n\t\tLEFT JOIN " . TABLE_CITY . " ct ON (ob.city_id=ct.city_id)\n\tWHERE\n\t\t{$where} AND z.clients") or Error(1, __FILE__, __LINE__);
while ($info = @mysql_fetch_array($sql)) {
    $current_client_arr = explode(",", $info['clients']);
    $client_arr = array_merge($client_arr, $current_client_arr);
    if ($reverse) {
        if (!isset($object_mega_arr[$info['object_id']])) {
            $object_mega_arr[$info['object_id']]['object'] = $info['object'];
            $object_mega_arr[$info['object_id']]['city'] = $info['city'];