function Questions_view($open_questions, $answered_questions, $ask_action) { foreach ($open_questions as &$question) { $question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>'; $question['Question'] = str_replace("\n", '<br />', $question['Question']); } foreach ($answered_questions as &$question) { $question['Question'] = str_replace("\n", '<br />', $question['Question']); $question['Answer'] = str_replace("\n", '<br />', $question['Answer']); $question['actions'] = '<a href="' . page_link_to("user_questions") . '&action=delete&id=' . $question['QID'] . '">' . _("delete") . '</a>'; } return page_with_title(questions_title(), array(msg(), '<h2>' . _("Open questions") . '</h2>', table(array('Question' => _("Question"), 'actions' => ""), $open_questions), '<h2>' . _("Answered questions") . '</h2>', table(array('Question' => _("Question"), 'answer_user' => _("Answered by"), 'Answer' => _("Answer"), 'actions' => ""), $answered_questions), '<h2>' . _("Ask an archangel") . '</h2>', form(array(form_textarea('question', _("Your Question:"), ""), form_submit('submit', _("Save"))), $ask_action))); }
function user_questions() { global $user; if (!isset($_REQUEST['action'])) { $open_questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'"); $answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'"); foreach ($answered_questions as &$question) { $answer_user_source = User($question['AID']); if ($answer_user_source === false) { engelsystem_error(_("Unable to load user.")); } $question['answer_user'] = User_Nick_render($answer_user_source); } return Questions_view($open_questions, $answered_questions, page_link_to("user_questions") . '&action=ask'); } else { switch ($_REQUEST['action']) { case 'ask': $question = strip_request_item_nl('question'); if ($question != "") { $result = sql_query("INSERT INTO `Questions` SET `UID`='" . sql_escape($user['UID']) . "', `Question`='" . sql_escape($question) . "'"); if ($result === false) { engelsystem_error(_("Unable to save question.")); } success(_("You question was saved.")); redirect(page_link_to("user_questions")); } else { return page_with_title(questions_title(), array(error(_("Please enter a question!"), true))); } break; case 'delete': if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}\$/", $_REQUEST['id'])) { $id = $_REQUEST['id']; } else { return error(_("Incomplete call, missing Question ID."), true); } $question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1"); if (count($question) > 0 && $question[0]['UID'] == $user['UID']) { sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($id) . "' LIMIT 1"); redirect(page_link_to("user_questions")); } else { return page_with_title(questions_title(), array(error(_("No question found."), true))); } break; } } }
$title = user_news_comments_title(); $content = user_news_comments(); } elseif ($p == "user_meetings") { $title = meetings_title(); $content = user_meetings(); } elseif ($p == "user_myshifts") { $title = myshifts_title(); $content = user_myshifts(); } elseif ($p == "user_shifts") { $title = shifts_title(); $content = user_shifts(); } elseif ($p == "user_messages") { $title = messages_title(); $content = user_messages(); } elseif ($p == "user_questions") { $title = questions_title(); $content = user_questions(); } elseif ($p == "user_settings") { $title = settings_title(); $content = user_settings(); } elseif ($p == "login") { $title = login_title(); $content = guest_login(); } elseif ($p == "register") { $title = register_title(); $content = guest_register(); } elseif ($p == "logout") { $title = logout_title(); $content = guest_logout(); } elseif ($p == "admin_questions") { $title = admin_questions_title();
function make_navigation() { global $p, $privileges; $menu = array(); $pages = array("news" => news_title(), "user_meetings" => meetings_title(), "user_shifts" => shifts_title(), "angeltypes" => angeltypes_title(), "user_questions" => questions_title()); foreach ($pages as $page => $title) { if (in_array($page, $privileges)) { $menu[] = toolbar_item_link(page_link_to($page), '', $title, $page == $p); } } $admin_menu = array(); $admin_pages = array("admin_arrive" => admin_arrive_title(), "admin_active" => admin_active_title(), "admin_user" => admin_user_title(), "admin_free" => admin_free_title(), "admin_questions" => admin_questions_title(), "shifttypes" => shifttypes_title(), "admin_shifts" => admin_shifts_title(), "admin_rooms" => admin_rooms_title(), "admin_groups" => admin_groups_title(), "admin_import" => admin_import_title(), "admin_log" => admin_log_title()); foreach ($admin_pages as $page => $title) { if (in_array($page, $privileges)) { $admin_menu[] = toolbar_item_link(page_link_to($page), '', $title, $page == $p); } } if (count($admin_menu) > 0) { $menu[] = toolbar_dropdown('', _("Admin"), $admin_menu); } return toolbar($menu); }