public static function FetchByRole($role) { global $db_connection; $res = array(); $from_table = TextPart::$table; $lang = GetLanguage(); if ($lang !== 'rus') { $from_table .= '_' . $lang; } $result = $db_connection->query("SELECT * FROM `" . $from_table . "` WHERE role=\"" . htmlspecialchars($role) . "\" ORDER BY priority DESC"); if (!$result) { echo $db_connection->error; return NULL; } while ($row = $result->fetch_assoc()) { $row['language'] = $lang; array_push($res, TextPart::FetchFromAssoc($row)); } return $res; }
public static function FetchBy($kwargs) { extract($kwargs, EXTR_PREFIX_ALL, 't'); $select_list = '*'; $eq_conds = array(); $order_by = ''; $limit = ''; $offset = ''; $where_addition = ''; $is_assoc = false; $is_unique = false; $special = array(); if (isset($t_select_list)) { $select_list = $t_select_list; } if (isset($t_eq_conds)) { $eq_conds = $t_eq_conds; } if (isset($t_order_by)) { $order_by = $t_order_by; } if (isset($t_limit)) { $limit = $t_limit; } if (isset($t_offset)) { $offset = $t_offset; } if (isset($t_where_addition)) { $where_addition = $t_where_addition; } if (isset($t_is_assoc)) { $is_assoc = $t_is_assoc; } if (isset($t_is_unique)) { $is_unique = $t_is_unique; } if (isset($t_special)) { $special = $t_special; } global $db_connection; $where_clause = ''; $i = 0; $size = count($eq_conds); $need_where_word = $size !== 0 || StringNotEmpty($where_addition); foreach ($eq_conds as $key => $value) { $value_tmp = $db_connection->real_escape_string($value); if (is_string($value_tmp)) { $value_tmp = '"' . $value_tmp . '"'; } $where_clause .= ' (' . $key . ' = ' . $value_tmp . ') '; if ($i < $size - 1) { $where_clause .= 'OR'; } ++$i; } if ($need_where_word) { if (StringNotEmpty($where_clause) && StringNotEmpty($where_addition)) { $where_clause = '(' . $where_clause . ') AND '; $where_addition = '(' . $where_addition . ')'; } $where_clause = "WHERE " . $where_clause . ' ' . $where_addition; } if (StringNotEmpty($order_by)) { $where_clause .= ' ORDER BY ' . $order_by; } if (StringNotEmpty($limit)) { $where_clause .= ' LIMIT ' . $limit; } if (StringNotEmpty($offset)) { $where_clause .= ' OFFSET ' . $offset; } if (!StringNotEmpty($lang)) { $lang = GetLanguage(); } $from_table = self::$table; $res = $db_connection->query("SELECT " . $select_list . " FROM " . $from_table . " " . $where_clause); if (!$res) { return new Error($db_connection->error, Error::db_error); } $res = self::ArrayFromDBResult($res, $is_assoc); $res_count = count($res); if ($is_unique) { if ($res_count > 1) { return Error::ambiguously; } if ($res_count === 0) { return Error::not_found; } } for ($i = 0, $count = count($special); $i < $count; ++$i) { switch ($special[$i]) { default: break; } } if (!$is_unique) { return $res; } else { return $res[0]; } }
function special_callback($kw, $rc) { extract($kw, EXTR_PREFIX_ALL, 't'); $special = array(); $is_assoc = false; $class_parent = NULL; if (isset($t_special)) { $special = $t_special; } if (isset($t_is_assoc)) { $is_assoc = $t_is_assoc; } if (isset($t_class_parent)) { $class_parent = $t_class_parent; } $res_count = count($rc); for ($i = 0, $count = count($special); $i < $count; ++$i) { switch ($special[$i]) { case 'author_link': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($rc[$j]['author_id'])) { $rc[$j]['author_link'] = User::FetchBy(['select_list' => 'id, name, surname', 'eq_conds' => ['id' => $rc[$j]['author_id']], 'is_unique' => true])->LinkToThis('btn-sm'); } } break; case 'link_to_full': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($rc[$j]['id']) && isset($rc[$j]['name'])) { $rc[$j]['link_to_full'] = $class_parent::LinkToThisUnsafe($rc[$j]['id'], $rc[$j]['name'], 'btn-sm', array('style' => 'color: black;')); } } break; case 'full_vers_link': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($rc[$j]['id'])) { $rc[$j]['full_vers_link'] = $class_parent::ToHTMLFullVersUnsafe($rc[$j]['id'], true); } } break; case 'path_to_image': global $image_extensions; global $link_to_article_images; global $link_to_service_images; if ($is_assoc) { for ($j = 0; $j < $res_count; ++$j) { if (!isset($rc[$j]['id'])) { continue; } $path = PathToImage($link_to_article_images . $rc[$j]['id'], 'cover', $link_to_service_images . 'Logo.png', $image_extensions, GetLanguage()); $rc[$j]['path_to_image'] = $path; } } else { for ($j = 0; $j < $res_count; ++$j) { $path = PathToImage($link_to_article_images . $rc[$j]->GetID(), 'cover', $link_to_service_images . 'Logo.png', $image_extensions, GetLanguage()); $rc[$j]['path_to_image'] = $path; } } break; default: break; } } return $rc; }
public function __construct($id = id_undef, $author_id = id_undef, $name = undef, $text_block = undef) { $this->id = $id; $this->author_id = $author_id; $this->name = $name; $this->text_block = $text_block; $this->language = GetLanguage(); }
public static function FetchAll() { global $db_connection; $res = array(); $from_table = Direction::$table; $lang = GetLanguage(); if ($lang != 'rus') { $from_table .= '_' . $lang; } $result = $db_connection->query("SELECT * FROM `" . $from_table . "` ORDER BY id DESC"); if (!$result) { return NULL; } while ($row = $result->fetch_assoc()) { $row['language'] = $lang; array_push($res, Direction::FetchFromAssoc($row)); } return $res; }
public static function FetchBy($kwargs) { extract($kwargs, EXTR_PREFIX_ALL, 't'); $select_list = '*'; $eq_conds = array(); $order_by = ''; $limit = ''; $offset = ''; $where_addition = ''; $is_assoc = false; $is_unique = false; $special = array(); if (isset($t_select_list)) { $select_list = $t_select_list; } if (isset($t_eq_conds)) { $eq_conds = $t_eq_conds; } if (isset($t_order_by)) { $order_by = $t_order_by; } if (isset($t_limit)) { $limit = $t_limit; } if (isset($t_offset)) { $offset = $t_offset; } if (isset($t_where_addition)) { $where_addition = $t_where_addition; } if (isset($t_is_assoc)) { $is_assoc = $t_is_assoc; } if (isset($t_is_unique)) { $is_unique = $t_is_unique; } if (isset($t_special)) { $special = $t_special; } global $db_connection; $where_clause = ''; $i = 0; $size = count($eq_conds); $need_where_word = $size !== 0 || StringNotEmpty($where_addition); foreach ($eq_conds as $key => $value) { $value_tmp = $db_connection->real_escape_string($value); if (is_string($value)) { $value_tmp = '"' . $value_tmp . '"'; } $where_clause .= ' (' . $key . ' = ' . $value_tmp . ') '; if ($i < $size - 1) { $where_clause .= 'OR'; } ++$i; } if ($need_where_word) { if (StringNotEmpty($where_clause) && StringNotEmpty($where_addition)) { $where_clause = '(' . $where_clause . ') AND '; $where_addition = '(' . $where_addition . ')'; } $where_clause = "WHERE " . $where_clause . ' ' . $where_addition; } if (StringNotEmpty($order_by)) { $where_clause .= ' ORDER BY ' . $order_by; } if (StringNotEmpty($limit)) { $where_clause .= ' LIMIT ' . $limit; } if (StringNotEmpty($offset)) { $where_clause .= ' OFFSET ' . $offset; } if (!StringNotEmpty($lang)) { $lang = GetLanguage(); } $from_table = self::$table; $res = $db_connection->query("SELECT " . $select_list . " FROM " . $from_table . " " . $where_clause); if (!$res) { return new Error($db_connection->error, Error::db_error); } $res = self::ArrayFromDBResult($res, $is_assoc); $res_count = count($res); if ($is_unique) { if ($res_count > 1) { return Error::ambiguously; } if ($res_count === 0) { return Error::not_found; } } for ($i = 0, $count = count($special); $i < $count; ++$i) { switch ($special[$i]) { case 'file_type': if ($is_assoc === false) { break; } global $valid_extensions; for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['name'])) { $type = fileExtension($res[$j]['name']); if (!in_array($type, $valid_extensions)) { $type = 'file'; } $res[$j]['file_type'] = $type; } } break; case 'link_to_download': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['path_to_file']) && isset($res[$j]['name']) && isset($res[$j]['is_directory'])) { $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'is_directory' => $res[$j]['is_directory']]); $res[$j]['link_to_download'] = $tmp->GetLinkToFile(); } } break; case 'link_to_delete': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) { $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]); $res[$j]['link_to_delete'] = $tmp->GetLinkToDelete(); } } break; case 'link_to_edit': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) { $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]); $res[$j]['link_to_edit'] = $tmp->GetLinkToEdit(); } } break; case 'link_to_link_to_download': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) { $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'id' => $res[$j]['id']]); $link = $tmp->CreateDownloadLink(); $res[$j]['link_to_link_to_download'] = SecretLink::WrapLinkToButton($link->GetPublicLink()); } } break; default: break; } } if (!$is_unique) { return $res; } else { return $res[0]; } }
$cdate = GetMsg("CREATED", $quiz->get_cdate()); echo "<tr><td>{$cdate}</td></tr>"; } if ($witheditor && count($quiz->get_editors())) { echo "<tr><td><table>"; echo "<tr><td colspan=\"2\">", GetMsg("EDITORS"), "</td></tr>\n"; foreach ($quiz->get_editors() as $editor) { echo "<tr>"; echo "<td>", $editor->get_name(), "</td>"; echo "<td>", $editor->get_email(), "</td>"; echo "<tr>"; } echo "</table></td></tr>"; } if ($withlanguage && $quiz->get_language()) { $cdate = GetMsg("LANGUAGE", GetLanguage($quiz->get_language())); echo "<tr><td>{$cdate}</td></tr>"; } // end formattabelle echo "</table></div>"; } /* echo "<tr><td><pre>"; print_r( $qf ); echo "</pre></td></tr>"; */ echo <<<EOT </td> <td background="style/{$style}/hggif/trrr.gif"></td> </tr>
function PathToImage($start_path, $image_name, $default_ans = '#default#', $available = array('bmp', 'gif', 'jpg', 'jpe', 'png', 'jpeg', 'svg'), $lang = '') { if ($lang === '') { $lang = GetLanguage(); } return PathToFile($start_path, $image_name, $default_ans, $available, $lang); }
function Address($lang = 0) { if ($lang === 0) { $lang = GetLanguage(); } switch ($lang) { case 'rus': return '119991 ГСП-1 Москва, Ленинские горы, МГУ имени М.В. Ломоносова, 2-й учебный корпус, факультет ВМК, этаж 5, аудитория 528<br><br>Телефон: 8-495-930-52-87'; case 'eng': return '119991 GSP-1 Moscow, Leninskie Gory, Lomonosov MSU, 2nd educational building, CMC faculty, 5-th floor, audience 528<br><br>Telephone: 8-495-930-52-87'; default: return 'incorrect language'; } }