コード例 #1
0
ファイル: votes.php プロジェクト: fedeB-IT-dept/fedeB_website
function get_votes_from_thread($thread_id)
{
    $retour = array("pro_votes" => 0, "against_votes" => 0, "choice" => 0);
    $rights = user_privilege_level();
    if ($rights > 1) {
        if ($rights > 2) {
            // Vaut-il mieux faire porter la charge sur le serveur SQL en utilisant deux requ�tes dont une v�rifiant les hashs, ou sur ecole.org en effectuant les v�rifications dans la boucle PHP ?
            $result = @mysql_query(sprintf("SELECT vote_id,rand_prop,hash_prop,vote FROM vote WHERE thread_id='%s'", mysql_real_escape_string($thread_id)));
            if ($result) {
                while ($row = mysql_fetch_assoc($result)) {
                    if ($row["vote"] == 1) {
                        $retour["pro_votes"]++;
                        if (check_property($row["rand_prop"], $row["hash_prop"])) {
                            $retour["choice"] = $row["vote_id"];
                            // On note un vote pour et l'ID du vote
                        }
                    } elseif ($row["vote"] == 0) {
                        $retour["against_votes"]++;
                        if (check_property($row["rand_prop"], $row["hash_prop"])) {
                            $retour["choice"] = -1 * $row["vote_id"];
                            // On note un vote contre et l'ID du vote
                        }
                    }
                }
                @mysql_free_result($result);
            } else {
                $retour["pro_votes"] = -1;
                $retour["against_votes"] = -1;
            }
        } else {
            $result = @mysql_query(sprintf("SELECT SUM(vote) AS pro_vote, count(vote) AS total_vote FROM vote WHERE thread_id='%s'", mysql_real_escape_string($thread_id)));
            if ($result && ($row = mysql_fetch_assoc($result))) {
                if (!isset($row["pro_vote"])) {
                    $row["pro_vote"] = 0;
                }
                if (!isset($row["total_vote"])) {
                    $row["total_vote"] = 0;
                }
                $retour["pro_votes"] = $row["pro_vote"];
                $retour["against_votes"] = $row["total_vote"] - $row["pro_vote"];
                @mysql_free_result($result);
            } else {
                $retour["pro_votes"] = -1;
                $retour["against_votes"] = -1;
            }
        }
    } else {
        $retour["pro_votes"] = -1;
        $retour["against_votes"] = -1;
    }
    return $retour;
}
コード例 #2
0
ファイル: posts.php プロジェクト: fedeB-IT-dept/fedeB_website
function display_post()
{
    $privileges = user_privilege_level();
    if ($privileges > 1) {
        // Titre et messages éventuels
        echo '<h1>Consultation des propositions :</h1>
		<h2>Pour voter, il faut s\'inscrire <a href="index.php?action=create_account" title="inscription">ICI</a></h2>';
        if (isset($_SESSION['transient_display'])) {
            echo $_SESSION['transient_display'];
            unset($_SESSION['transient_display']);
        }
        // ******************************************************************* //
        // Formulaire pour gérer le filtrage/l'ordonnancement des propositions //
        // ******************************************************************* //
        // Menu de sélection des idées
        $tail = '<div class="enlarge_lowresol">
			<form method="post" action="?action=post_filter_change">
				<table class="tab_form_close">
					<tr>';
        // Choix de catégorie
        $tail .= '<td>
							Cat&eacute;gorie :
						</td>
						<td>
							<select name="category_filter">
								<option value="0">Toutes</option>';
        $result = @mysql_query("SELECT category_id,category_name FROM thread_category");
        // Menu déroulant de choix de catégorie en fonction de ce qui est disponible en base
        if ($result) {
            while ($row = mysql_fetch_assoc($result)) {
                if (isset($_SESSION["thread_category_filter"]) && $row["category_id"] == $_SESSION["thread_category_filter"]) {
                    $tail .= '<option value="' . htmlentities($row["category_id"]) . '" selected="selected">' . htmlentities($row["category_name"]) . '</option>';
                } else {
                    $tail .= '<option value="' . htmlentities($row["category_id"]) . '">' . htmlentities($row["category_name"]) . '</option>';
                }
            }
            @mysql_free_result($result);
        }
        $tail .= '</select></td>';
        // Menu de filtrage pour les utilisateurs loggés
        if (is_logged()) {
            $tail .= '<td>
				Filtre :
			</td>
			<td>
				<select name="admin_filter">
					<option value="0">Aucun</option>';
            if ($privileges > 3) {
                if (isset($_SESSION["thread_admin_filter"])) {
                    switch ($_SESSION["thread_admin_filter"]) {
                        case 1:
                            $tail .= '<option value="1" selected="selected">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 2:
                            $tail .= '<option value="1">Mes propositions</option><option value="2" selected="selected">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 3:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3" selected="selected">Propositions sans mon vote</option>
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 4:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>
								<option value="4" selected="selected">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 5:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5" selected="selected">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        default:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                    }
                } else {
                    $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>
						<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                }
            } else {
                if (isset($_SESSION["thread_admin_filter"])) {
                    switch ($_SESSION["thread_admin_filter"]) {
                        case 1:
                            $tail .= '<option value="1" selected="selected">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                            break;
                        case 2:
                            $tail .= '<option value="1">Mes propositions</option><option value="2" selected="selected">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                            break;
                        case 3:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3" selected="selected">Propositions sans mon vote</option>';
                            break;
                        default:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                    }
                } else {
                    $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                }
            }
            $tail .= '</select></td>';
        }
        // Menu pour le tri des résultats
        if (isset($_SESSION["thread_ordering"])) {
            if (isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 5) {
                $tail .= '<td>
							Trier par :
						</td>
						<td>
							<select name="sorting" disabled="disabled">
								<option value="1" selected="selected">Date</option><option value="2">Nombre de votes favorables</option><option value="3">Proportion de votes favorables</option><option value="4">Nombre total de votes</option>"';
            } else {
                $tail .= '<td>
							Trier par :
						</td>
						<td>
							<select name="sorting">';
                switch ($_SESSION["thread_ordering"]) {
                    case 1:
                        $tail .= "<option value=\"1\" selected=\"selected\">Date</option><option value=\"2\">Nombre de votes favorables</option><option value=\"3\">Proportion de votes favorables</option><option value=\"4\">Nombre total de votes</option>";
                        break;
                    case 2:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\" selected=\"selected\">Nombre de votes favorables</option><option value=\"3\">Proportion de votes favorables</option><option value=\"4\">Nombre total de votes</option>";
                        break;
                    case 3:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\">Nombre de votes favorables</option><option value=\"3\" selected=\"selected\">Proportion de votes favorables</option><option value=\"4\">Nombre total de votes</option>";
                        break;
                    case 4:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\">Nombre de votes favorables</option><option value=\"3\">Proportion de votes favorables</option><option value=\"4\" selected=\"selected\">Nombre total de votes</option>";
                        break;
                    default:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\">Nombre de votes favorables</option><option value=\"3\">Proportion de votes favorables</option><option value=\"4\">Nombre total de votes</option>";
                }
            }
        } else {
            if (isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 4) {
                $tail .= '<td>
							Trier par :
						</td>
						<td>
							<select name="sorting" disabled="disabled">
								<option value="1">Date</option><option value="2">Nombre de votes favorables</option><option value="3">Proportion de votes favorables</option><option value="4">Nombre total de votes</option>"';
            } else {
                $tail .= '<td>
							Trier par :
						</td>
						<td>
							<select name="sorting">
								<option value="1">Date</option><option value="2">Nombre de votes favorables</option><option value="3">Proportion de votes favorables</option><option value="4">Nombre total de votes</option>';
            }
        }
        echo $tail . '
						</select>
					</td>
					<td>
						<input type="hidden" name="form_name" value="thread_display_param" />
					</td>
					<td>
						<input type="submit" value="Valider" />
					</td>
				</tr>
			</table>
		</form></div>';
        $is_admin = $privileges > 3;
        // ****************************************************************************** //
        // Affichage des résultats selon les paramètres définis dans les menus précédents //
        // ****************************************************************************** //
        if (isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 5) {
            affichage_comments(-1, true);
            // Affichage "brutal" des commentaires confié à une autre fonction
        } else {
            $current_mod = isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 4;
            // Mode modération
            $vote_filt = isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 3;
            // Filtrage selon les votes
            // ************************************************************ //
            // Construction de la requête de rappatriement des propositions //
            // ************************************************************ //
            $recherche = "(T.text LIKE '%" . mysql_real_escape_string($_SESSION['thread_admin_recherche']) . "%' OR T.title LIKE '%" . mysql_real_escape_string($_SESSION['thread_admin_recherche']) . "%') AND";
            // Requête de base (deux parties pour prendre en comptes les propositions sans votes)
            $query_p1 = "(SELECT T.thread_id, T.rand_prop, T.hash_prop, T.title, T.text, T.date, T.is_valid, T.possibly_name, T.already_mod, G.category_name,\n\t\t\t\t\tSUM(V.vote) AS pro_vote, COUNT(V.vote) AS total_vote\n\t\t\t\t\tFROM thread T, thread_category G, vote V\n\t\t\t\t\tWHERE " . $recherche . " V.thread_id=T.thread_id AND G.category_id=T.category";
            $query_p2 = "(SELECT T.thread_id, T.rand_prop, T.hash_prop, T.title, T.text, T.date, T.is_valid, T.possibly_name, T.already_mod, G.category_name,\n\t\t\t\t\t0 AS pro_vote, 0 AS total_vote\n\t\t\t\t\tFROM thread T, thread_category G\n\t\t\t\t\tWHERE " . $recherche . " T.thread_id <> ALL (SELECT thread_id FROM vote) AND G.category_id=T.category";
            $query_count = "SELECT COUNT(T.thread_id) AS NUM_RES FROM thread T, thread_category G WHERE G.category_id=T.category";
            // Requête à part pour déterminer préalablement le nombre de résultats
            if (isset($_SESSION["thread_admin_filter"])) {
                switch ($_SESSION["thread_admin_filter"]) {
                    case 0:
                        // Aucune contrainte si ce n'est une question de droits d'affichage
                        if (is_logged()) {
                            if (!$is_admin) {
                                $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            }
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 1:
                        // Posts propriétaires
                        if (is_logged()) {
                            $query_p1 .= sprintf(" AND (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop)", mysql_real_escape_string($_SESSION['login_c']));
                            $query_p2 .= sprintf(" AND (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop)", mysql_real_escape_string($_SESSION['login_c']));
                            $query_count .= sprintf(" AND (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop)", mysql_real_escape_string($_SESSION['login_c']));
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 2:
                        // Posts commentés
                        if (is_logged()) {
                            $query_p1 .= sprintf(" AND T.thread_id IN (SELECT DISTINCT thread_id FROM comment WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_p2 .= sprintf(" AND T.thread_id IN (SELECT DISTINCT thread_id FROM comment WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_count .= sprintf(" AND T.thread_id IN (SELECT DISTINCT thread_id FROM comment WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            if (!$is_admin) {
                                $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            }
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 3:
                        // Posts pour lesquels je n'ai pas voté
                        if (is_logged()) {
                            $query_p1 .= sprintf(" AND T.thread_id NOT IN (SELECT DISTINCT thread_id FROM vote WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_p2 .= sprintf(" AND T.thread_id NOT IN (SELECT DISTINCT thread_id FROM vote WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_count .= sprintf(" AND T.thread_id NOT IN (SELECT DISTINCT thread_id FROM vote WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            if (!$is_admin) {
                                $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            }
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 4:
                        // Propositions non modérées
                        if ($is_admin) {
                            $query_p1 .= " AND T.already_mod=0";
                            $query_p2 .= " AND T.already_mod=0";
                            $query_count .= " AND T.already_mod=0";
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    default:
                        // Dans le doute
                        $query_p1 .= " AND FALSE";
                        $query_p2 .= " AND FALSE";
                        $query_count .= " AND FALSE";
                }
            } else {
                if (!$is_admin) {
                    if (is_logged()) {
                        $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                        $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                        $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                    } else {
                        $query_p1 .= " AND T.is_valid=1";
                        $query_p2 .= " AND T.is_valid=1";
                        $query_count .= " AND T.is_valid=1";
                    }
                }
            }
            // Filtrage éventuel selon la catégorie
            if (isset($_SESSION["thread_category_filter"]) && $_SESSION["thread_category_filter"] > 0) {
                $category_searched = mysql_real_escape_string($_SESSION["thread_category_filter"]);
                $query_p1 .= " AND T.category={$category_searched}";
                $query_p2 .= " AND T.category={$category_searched}";
                $query_count .= " AND T.category={$category_searched}";
            }
            // Regroupement propositions avec/sans votes
            $query = $query_p1 . ' GROUP BY T.thread_id, T.rand_prop, T.hash_prop, T.title, T.text, T.date, T.is_valid, T.possibly_name, G.category_name) UNION ' . $query_p2 . ')';
            // Détermination du nombre résultats potentiellement retournés, pour connaître la répartition par pages
            $num_res = -1;
            // Valeur par défaut en cas d'échec
            $res = @mysql_query($query_count);
            if ($res) {
                if ($num_res = mysql_fetch_assoc($res)) {
                    $num_res = $num_res["NUM_RES"];
                }
                @mysql_free_result($res);
            }
            // Suite de la construction de la requête, GROUP et ORDER BY
            if (isset($_SESSION["thread_ordering"])) {
                switch ($_SESSION["thread_ordering"]) {
                    case 2:
                        $query .= " ORDER BY pro_vote DESC";
                        break;
                    case 3:
                        $query .= " ORDER BY pro_vote/total_vote DESC";
                        break;
                    case 4:
                        $query .= " ORDER BY total_vote DESC";
                        break;
                    default:
                        $query .= " ORDER BY date DESC";
                        break;
                }
            } else {
                $query .= " ORDER BY date DESC";
            }
            // Fin de la construction de la requête, LIMIT selon la page affichée
            $page_to_display = 1;
            if (!isset($_SESSION["thread_page"])) {
                $_SESSION["thread_page"] = 1;
            } else {
                $page_to_display = $_SESSION["thread_page"];
                if (!is_numeric($page_to_display) || $page_to_display < 1) {
                    $_SESSION["thread_page"] = 1;
                    $page_to_display = 1;
                }
            }
            if ($num_res > -1) {
                $offset = round(10 * ($page_to_display - 1));
                if ($offset >= $num_res) {
                    $offset = 0;
                    $_SESSION["thread_page"] = 1;
                }
                $query .= " LIMIT {$offset},10";
            }
            // ********************************************************************* //
            // Menu de changement de page, sauvegardé pour affichage en base de page //
            // ********************************************************************* //
            $change_page = "";
            if ($num_res > 10) {
                $change_page .= '<div class="bottom_page_choice">';
                for ($i = 1; $i < ceil($num_res / 10) + 1; $i++) {
                    if ($i == $_SESSION["thread_page"]) {
                        $change_page .= "{$i}&nbsp;&nbsp;";
                    } else {
                        $change_page .= '<a href="?action=change_thread_page&amp;num_page=' . $i . '">' . $i . '</a>&nbsp;&nbsp;';
                    }
                }
                $change_page .= '</div><br/>';
                echo $change_page;
            } else {
                echo '<br />';
            }
            ////////////////////////////////////////////////////////
            // Exécution de la requête et affichage des résultats //
            ////////////////////////////////////////////////////////
            $result = @mysql_query($query);
            if ($result) {
                $result_returned = false;
                $need_separator = false;
                while ($row = mysql_fetch_assoc($result)) {
                    // Informations diverses sur le post
                    $result_returned = true;
                    $thread_id = $row["thread_id"];
                    $thread_id_affiche = htmlentities($thread_id);
                    $is_proprio = check_property($row["rand_prop"], $row["hash_prop"]);
                    $is_valid = $row["is_valid"];
                    $already_mod = $row["already_mod"];
                    $check_vote = get_votes_from_thread($thread_id);
                    $pro_vote = $check_vote["pro_votes"];
                    $agt_vote = $check_vote["against_votes"];
                    $per_vote = $check_vote["choice"];
                    // Hormis l'auteur ou un administrateur, affichage uniquement si le post a été modéré
                    if ($is_valid || $is_proprio || $privileges > 3) {
                        if ($need_separator) {
                            echo '<div class="newsterminator">
									<hr />
								</div>';
                        }
                        $need_separator = true;
                        // Titre et état de modération
                        echo '<span class="newstitle" id="' . $thread_id_affiche . '">
								' . htmlentities(stripslashes($row["title"])) . ' [#' . $thread_id_affiche . ']
							</span>';
                        if ($privileges > 3) {
                            if ($already_mod) {
                                if ($is_valid) {
                                    echo '<img src="rep_img/modere.png" alt="Mod&eacute;r&eacute;" class="imgtitlenews" />';
                                } else {
                                    echo '<img src="rep_img/masque.png" alt="Masqu&eacute;" class="imgtitlenews" />';
                                }
                            } else {
                                echo '<img src="rep_img/n_modere.png" alt="Non mod&eacute;r&eacute;" class="imgtitlenews" />';
                            }
                        } elseif ($is_proprio) {
                            if ($already_mod) {
                                if (!$is_valid) {
                                    echo '<img src="rep_img/masque.png" alt="Masqu&eacute;" class="imgtitlenews" />';
                                }
                            } else {
                                echo '<img src="rep_img/n_modere.png" alt="Non mod&eacute;r&eacute;" class="imgtitlenews" />';
                            }
                        }
                        // Votes
                        if ($privileges >= 2) {
                            echo '<span class="vote">';
                            if ($per_vote > 0) {
                                echo '<a href="?action=vote_post&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="rep_img/bright_votepro.png" alt="+1" class="imgvote" /></a>';
                            } else {
                                if ($vote_filt) {
                                    echo '<a href="?action=vote_post&amp;order=1&amp;thread_id=' . $thread_id_affiche . '"><img src="rep_img/pale_votepro.png" alt="+1" class="imgvote" /></a>';
                                } else {
                                    echo '<a href="?action=vote_post&amp;order=1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="rep_img/pale_votepro.png" alt="+1" class="imgvote" /></a>';
                                }
                            }
                            if ($per_vote < 0) {
                                echo '<a href="?action=vote_post&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="rep_img/bright_voteneg.png" alt="-1" class="imgvote" /></a>';
                            } else {
                                if ($vote_filt) {
                                    echo '<a href="?action=vote_post&amp;order=-1&amp;thread_id=' . $thread_id_affiche . '"><img src="rep_img/pale_voteneg.png" alt="-1" class="imgvote" /></a>';
                                } else {
                                    echo '<a href="?action=vote_post&amp;order=-1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="rep_img/pale_voteneg.png" alt="-1" class="imgvote" /></a>';
                                }
                            }
                            echo '</span>';
                        }
                        // Contexte
                        echo '<div class="newsundertitle">
								' . htmlentities(transfo_date($row["date"])) . '&nbsp;-&nbsp;' . htmlentities($row["category_name"]);
                        if (!empty($row["possibly_name"])) {
                            echo '&nbsp;-&nbsp;' . htmlentities($row["possibly_name"]);
                        }
                        echo '</div>
						<div class="votebar">';
                        // Etat des votes
                        if ($pro_vote == 0) {
                            if ($agt_vote == 0) {
                                echo '<span class="neutralvote">
										<span class="votebarannotation">
											+0
										</span>
									</span>
								</div>';
                            } else {
                                echo '<span class="againstvote" style="height:100%;width:8px;">
										<span class="votebarannotation">
											-' . htmlentities($agt_vote) . '
										</span>
									</span>
								</div>';
                            }
                        } else {
                            if ($agt_vote == 0) {
                                echo '<span class="provote" style="height:100%;width:8px;">
										<span class="votebarannotation_pro">
											+' . htmlentities($pro_vote) . '
										</span>
									</span>
								</div>';
                            } else {
                                $prop_pro = round(100 * $pro_vote / ($agt_vote + $pro_vote));
                                echo '<span class="provote" style="height:' . $prop_pro . '%;width:8px;">
										<span class="votebarannotation_pro">
											+' . htmlentities($pro_vote) . '
										</span>
									</span>
									<span class="againstvote" style="height:' . (100 - $prop_pro) . '%;width:8px;">
										<span class="votebarannotation">
											-' . htmlentities($agt_vote) . '
										</span>
									</span>
								</div>';
                            }
                        }
                        // Corps
                        echo '<div class="newscontent">' . text_display_prepare($row["text"]) . '</div>';
                        echo '<div class="newsendlinks">';
                        if ($is_proprio || $privileges > 4) {
                            echo '
								<a href="?action=edit_post&amp;thread_id=' . $thread_id_affiche . '">Editer</a>
								<a href="?action=remove_post&amp;thread_id=' . $thread_id_affiche . '">Supprimer</a>';
                            if ($is_proprio) {
                                if (!empty($row["possibly_name"])) {
                                    echo '<a href="?action=anonymization&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">Masquer mon nom</a>';
                                } else {
                                    echo '<a href="?action=anonymization&amp;order=1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">Afficher mon nom</a>';
                                }
                            }
                        }
                        if ($is_admin) {
                            if ($is_valid || !$already_mod) {
                                if ($current_mod) {
                                    echo '<a href="?action=moderation&amp;order=0&amp;thread_id=' . $thread_id_affiche . '">Refuser</a>';
                                } else {
                                    echo '<a href="?action=moderation&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">Refuser</a>';
                                }
                            }
                            if (!$is_valid || !$already_mod) {
                                if ($current_mod) {
                                    echo '<a href="?action=moderation&amp;order=1&amp;thread_id=' . $thread_id_affiche . '">Accepter</a>';
                                } else {
                                    echo '<a href="?action=moderation&amp;order=1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">Accepter</a>';
                                }
                            }
                        }
                        // Affichage des commentaires - ferme le div newsendlinks
                        affichage_comments($thread_id, false);
                    }
                }
                // Affichage vide / d'un cadre de choix de page / d'un avertissement sur le nombre de résultats / selon les cas
                if ($result_returned) {
                    echo $change_page . '<div class="newsterminator"><hr />' . NOM_ECOLE . ' </div>';
                } else {
                    echo '<div class="warning">Aucune proposition n\'est disponible selon les critères choisis</div>';
                }
                @mysql_free_result($result);
            } else {
                echo '<div class="warning">Erreur lors de la requ&ecirc;te</div>';
            }
        }
    } else {
        need_ecole_member_privilege(2);
    }
}
コード例 #3
0
ファイル: posts.php プロジェクト: AnthonyReese/Refresh
function display_post()
{
    $privileges = user_privilege_level();
    if ($privileges > 1) {
        // Titre et messages éventuels
        if (isset($_SESSION['transient_display'])) {
            echo $_SESSION['transient_display'];
            unset($_SESSION['transient_display']);
        }
        // ******************************************************************* //
        // Formulaire pour gérer le filtrage/l'ordonnancement des propositions //
        // ******************************************************************* //
        // Menu de sélection des idées
        $tail = '<form class="row" method="post" action="?action=post_filter_change">
			<div class="tab_form_close">
					';
        // Champ de recherche
        $tail .= '<input class="span2" placeholder="' . _('Search...') . '"…" type="text" name="admin_recherche" value="' . $_SESSION["thread_admin_recherche"] . '">';
        // Choix de catégorie
        $tail .= '<select class="span2" name="category_filter">
				<option value="0">' . _('Cat&eacute;gories') . '</option>';
        $result = @mysql_query("SELECT category_id,category_name FROM thread_category");
        // Menu déroulant de choix de catégorie en fonction de ce qui est disponible en base
        if ($result) {
            while ($row = mysql_fetch_assoc($result)) {
                if (isset($_SESSION["thread_category_filter"]) && $row["category_id"] == $_SESSION["thread_category_filter"]) {
                    $tail .= '<option value="' . htmlentities($row["category_id"]) . '" selected="selected">' . htmlentities($row["category_name"]) . '</option>';
                } else {
                    $tail .= '<option value="' . htmlentities($row["category_id"]) . '">' . htmlentities($row["category_name"]) . '</option>';
                }
            }
            @mysql_free_result($result);
        }
        $tail .= '</select>';
        // Menu de filtrage pour les utilisateurs loggés
        if (is_logged()) {
            $tail .= '<select class="span2" name="admin_filter">
					<option value="0">' . _('No filter') . '</option>';
            if ($privileges > 3) {
                if (isset($_SESSION["thread_admin_filter"])) {
                    switch ($_SESSION["thread_admin_filter"]) {
                        case 1:
                            $tail .= '<option value="1" selected="selected">' . _('My posts') . '</option><option value="2">' . _('Posts with my comments') . '</option><option value="3">Propositions sans mon vote</option> 
								<option value="4">' . _('Not moderated posts') . '</option><option value="5">' . _('Not moderated comments') . '</option>';
                            break;
                        case 2:
                            $tail .= '<option value="1">Mes propositions</option><option value="2" selected="selected">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option> 
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 3:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3" selected="selected">Propositions sans mon vote</option> 
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 4:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option> 
								<option value="4" selected="selected">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        case 5:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option> 
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5" selected="selected">Commentaires non mod&eacute;r&eacute;s</option>';
                            break;
                        default:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option> 
								<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                    }
                } else {
                    $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option> 
						<option value="4">Propositions non mod&eacute;r&eacute;es</option><option value="5">Commentaires non mod&eacute;r&eacute;s</option>';
                }
            } else {
                if (isset($_SESSION["thread_admin_filter"])) {
                    switch ($_SESSION["thread_admin_filter"]) {
                        case 1:
                            $tail .= '<option value="1" selected="selected">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                            break;
                        case 2:
                            $tail .= '<option value="1">Mes propositions</option><option value="2" selected="selected">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                            break;
                        case 3:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3" selected="selected">Propositions sans mon vote</option>';
                            break;
                        default:
                            $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                    }
                } else {
                    $tail .= '<option value="1">Mes propositions</option><option value="2">Propositions avec mes commentaires</option><option value="3">Propositions sans mon vote</option>';
                }
            }
            $tail .= '</select></td>';
        }
        // Menu pour le tri des résultats
        if (isset($_SESSION["thread_ordering"])) {
            if (isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 5) {
                $tail .= _('Sort by') . '
					<select name="sorting" class="span2" disabled="disabled">
								<option value="1" selected="selected">Date</option><option value="2">Upvotes number</option><option value="3">Upvotes ratio</option><option value="4">' . _('Votes total') . '</option>"';
            } else {
                $tail .= _('Sort by') . '
							<select class="span2" name="sorting">';
                switch ($_SESSION["thread_ordering"]) {
                    case 1:
                        $tail .= "<option value=\"1\" selected=\"selected\">Date</option><option value=\"2\">Upvotes number</option><option value=\"3\">Upvotes ratio</option><option value=\"4\">" . _('Votes total') . "</option>";
                        break;
                    case 2:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\" selected=\"selected\">Upvotes number</option><option value=\"3\">Upvotes ratio</option><option value=\"4\">" . _('Votes total') . "</option>";
                        break;
                    case 3:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\">Upvotes number</option><option value=\"3\" selected=\"selected\">Upvotes ratio</option><option value=\"4\">" . _('Votes total') . "</option>";
                        break;
                    case 4:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\">Upvotes number</option><option value=\"3\">Upvotes ratio</option><option value=\"4\" selected=\"selected\">" . _('Votes total') . "</option>";
                        break;
                    default:
                        $tail .= "<option value=\"1\">Date</option><option value=\"2\">Upvotes number</option><option value=\"3\">Upvotes ratio</option><option value=\"4\">" . _('Votes total') . "</option>";
                }
            }
        } else {
            if (isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 4) {
                $tail .= _('Sort by') . '
							<select  class="span2" name="sorting" disabled="disabled">
								<option value="1">Date</option><option value="2">Upvotes number</option><option value="3">Upvotes ratio</option><option value="4">' . _('Votes total') . '</option>"';
            } else {
                $tail .= _('Sort by') . '
							<select  class="span2" name="sorting">
								<option value="1">Date</option><option value="2">Upvotes number</option><option value="3">Upvotes ratio</option><option value="4">' . _('Votes total') . '</option>';
            }
        }
        echo $tail . '			
				</select>
				<input type="hidden" name="form_name" value="thread_display_param" />
				<input type="submit" value="Valider" />
			</div>
		</form>';
        $is_admin = $privileges > 3;
        // ****************************************************************************** //
        // Affichage des résultats selon les paramètres définis dans les menus précédents //
        // ****************************************************************************** //
        if (isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 5) {
            affichage_comments(-1, true);
            // Affichage "brutal" des commentaires confié à une autre fonction
        } else {
            $current_mod = isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 4;
            // Mode modération
            $vote_filt = isset($_SESSION["thread_admin_filter"]) && $_SESSION["thread_admin_filter"] == 3;
            // Filtrage selon les votes
            // ************************************************************ //
            // Construction de la requête de rappatriement des propositions //
            // ************************************************************ //
            $recherche = "(T.text LIKE '%" . mysql_real_escape_string($_SESSION['thread_admin_recherche']) . "%' OR T.title LIKE '%" . mysql_real_escape_string($_SESSION['thread_admin_recherche']) . "%') AND";
            // Requête de base (deux parties pour prendre en comptes les propositions sans votes)
            $query_p1 = "(SELECT T.thread_id, T.rand_prop, T.hash_prop, T.title, T.text, T.date, T.is_valid, T.possibly_name, T.already_mod, G.category_name,\n\t\t\t\t\tSUM(V.vote) AS pro_vote, COUNT(V.vote) AS total_vote\n\t\t\t\t\tFROM thread T, thread_category G, vote V\n\t\t\t\t\tWHERE " . $recherche . " V.thread_id=T.thread_id AND G.category_id=T.category";
            $query_p2 = "(SELECT T.thread_id, T.rand_prop, T.hash_prop, T.title, T.text, T.date, T.is_valid, T.possibly_name, T.already_mod, G.category_name,\n\t\t\t\t\t0 AS pro_vote, 0 AS total_vote\n\t\t\t\t\tFROM thread T, thread_category G \n\t\t\t\t\tWHERE " . $recherche . " T.thread_id <> ALL (SELECT thread_id FROM vote) AND G.category_id=T.category";
            $query_count = "SELECT COUNT(T.thread_id) AS NUM_RES FROM thread T, thread_category G WHERE G.category_id=T.category";
            // Requête à part pour déterminer préalablement le nombre de résultats
            if (isset($_SESSION["thread_admin_filter"])) {
                switch ($_SESSION["thread_admin_filter"]) {
                    case 0:
                        // Aucune contrainte si ce n'est une question de droits d'affichage
                        if (is_logged()) {
                            if (!$is_admin) {
                                $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            }
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 1:
                        // Posts propriétaires
                        if (is_logged()) {
                            $query_p1 .= sprintf(" AND (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop)", mysql_real_escape_string($_SESSION['login_c']));
                            $query_p2 .= sprintf(" AND (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop)", mysql_real_escape_string($_SESSION['login_c']));
                            $query_count .= sprintf(" AND (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop)", mysql_real_escape_string($_SESSION['login_c']));
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 2:
                        // Posts commentés
                        if (is_logged()) {
                            $query_p1 .= sprintf(" AND T.thread_id IN (SELECT DISTINCT thread_id FROM comment WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_p2 .= sprintf(" AND T.thread_id IN (SELECT DISTINCT thread_id FROM comment WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_count .= sprintf(" AND T.thread_id IN (SELECT DISTINCT thread_id FROM comment WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            if (!$is_admin) {
                                $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            }
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 3:
                        // Posts pour lesquels je n'ai pas voté
                        if (is_logged()) {
                            $query_p1 .= sprintf(" AND T.thread_id NOT IN (SELECT DISTINCT thread_id FROM vote WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_p2 .= sprintf(" AND T.thread_id NOT IN (SELECT DISTINCT thread_id FROM vote WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            $query_count .= sprintf(" AND T.thread_id NOT IN (SELECT DISTINCT thread_id FROM vote WHERE (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            if (!$is_admin) {
                                $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                                $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                            }
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    case 4:
                        // Propositions non modérées
                        if ($is_admin) {
                            $query_p1 .= " AND T.already_mod=0";
                            $query_p2 .= " AND T.already_mod=0";
                            $query_count .= " AND T.already_mod=0";
                        } else {
                            $query_p1 .= " AND FALSE";
                            $query_p2 .= " AND FALSE";
                            $query_count .= " AND FALSE";
                        }
                        break;
                    default:
                        // Dans le doute
                        $query_p1 .= " AND FALSE";
                        $query_p2 .= " AND FALSE";
                        $query_count .= " AND FALSE";
                }
            } else {
                if (!$is_admin) {
                    if (is_logged()) {
                        $query_p1 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                        $query_p2 .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))) AS CHAR)=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                        $query_count .= sprintf(" AND (T.is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(T.rand_prop AS CHAR))))=T.hash_prop))", mysql_real_escape_string($_SESSION['login_c']));
                    } else {
                        $query_p1 .= " AND T.is_valid=1";
                        $query_p2 .= " AND T.is_valid=1";
                        $query_count .= " AND T.is_valid=1";
                    }
                }
            }
            // Filtrage éventuel selon la catégorie
            if (isset($_SESSION["thread_category_filter"]) && $_SESSION["thread_category_filter"] > 0) {
                $category_searched = mysql_real_escape_string($_SESSION["thread_category_filter"]);
                $query_p1 .= " AND T.category={$category_searched}";
                $query_p2 .= " AND T.category={$category_searched}";
                $query_count .= " AND T.category={$category_searched}";
            }
            // Regroupement propositions avec/sans votes
            $query = $query_p1 . ' GROUP BY T.thread_id, T.rand_prop, T.hash_prop, T.title, T.text, T.date, T.is_valid, T.possibly_name, G.category_name) UNION ' . $query_p2 . ')';
            // Détermination du nombre résultats potentiellement retournés, pour connaître la répartition par pages
            $num_res = -1;
            // Valeur par défaut en cas d'échec
            $res = @mysql_query($query_count);
            if ($res) {
                if ($num_res = mysql_fetch_assoc($res)) {
                    $num_res = $num_res["NUM_RES"];
                }
                @mysql_free_result($res);
            }
            // Suite de la construction de la requête, GROUP et ORDER BY
            if (isset($_SESSION["thread_ordering"])) {
                switch ($_SESSION["thread_ordering"]) {
                    case 2:
                        $query .= " ORDER BY pro_vote DESC";
                        break;
                    case 3:
                        $query .= " ORDER BY pro_vote/total_vote DESC";
                        break;
                    case 4:
                        $query .= " ORDER BY total_vote DESC";
                        break;
                    default:
                        $query .= " ORDER BY date DESC";
                        break;
                }
            } else {
                $query .= " ORDER BY date DESC";
            }
            // Fin de la construction de la requête, LIMIT selon la page affichée
            $page_to_display = 1;
            if (!isset($_SESSION["thread_page"])) {
                $_SESSION["thread_page"] = 1;
            } else {
                $page_to_display = $_SESSION["thread_page"];
                if (!is_numeric($page_to_display) || $page_to_display < 1) {
                    $_SESSION["thread_page"] = 1;
                    $page_to_display = 1;
                }
            }
            if ($num_res > -1) {
                $offset = round(10 * ($page_to_display - 1));
                if ($offset >= $num_res) {
                    $offset = 0;
                    $_SESSION["thread_page"] = 1;
                }
                $query .= " LIMIT {$offset},10";
            }
            // ********************************************************************* //
            // Menu de changement de page, sauvegardé pour affichage en base de page //
            // ********************************************************************* //
            $change_page = "";
            if ($num_res > 10) {
                $change_page .= '<div class="bottom_page_choice">';
                for ($i = 1; $i < ceil($num_res / 10) + 1; $i++) {
                    if ($i == $_SESSION["thread_page"]) {
                        $change_page .= "{$i}&nbsp;&nbsp;";
                    } else {
                        $change_page .= '<a href="?action=change_thread_page&amp;num_page=' . $i . '">' . $i . '</a>&nbsp;&nbsp;';
                    }
                }
                $change_page .= '</div><br/>';
                echo $change_page;
            } else {
                echo '<br />';
            }
            ////////////////////////////////////////////////////////
            // Exécution de la requête et affichage des résultats //
            ////////////////////////////////////////////////////////
            $result = @mysql_query($query);
            if ($result) {
                $result_returned = false;
                $need_separator = false;
                while ($row = mysql_fetch_assoc($result)) {
                    // Informations diverses sur le post
                    $result_returned = true;
                    $thread_id = $row["thread_id"];
                    $thread_id_affiche = htmlentities($thread_id);
                    $is_proprio = check_property($row["rand_prop"], $row["hash_prop"]);
                    $is_valid = $row["is_valid"];
                    $already_mod = $row["already_mod"];
                    $check_vote = get_votes_from_thread($thread_id);
                    $pro_vote = $check_vote["pro_votes"];
                    $agt_vote = $check_vote["against_votes"];
                    $per_vote = $check_vote["choice"];
                    // Hormis l'auteur ou un administrateur, affichage uniquement si le post a été modéré
                    if ($is_valid || $is_proprio || $privileges > 3) {
                        if ($need_separator) {
                            echo '<hr />';
                        }
                        $need_separator = true;
                        echo '
						<article class="feed_item row" id="item-' . $thread_id_affiche . '"">
						<div class="span2">
						';
                        // Etat de modération
                        if ($privileges > 3) {
                            if ($already_mod) {
                                if ($is_valid) {
                                    echo '<img src="img/modere.png" alt="Mod&eacute;r&eacute;" class="imgtitlenews" />';
                                } else {
                                    echo '<img src="img/masque.png" alt="Masqu&eacute;" class="imgtitlenews" />';
                                }
                            } else {
                                echo '<img src="img/n_modere.png" alt="Non mod&eacute;r&eacute;" class="imgtitlenews" />';
                            }
                        } elseif ($is_proprio) {
                            if ($already_mod) {
                                if (!$is_valid) {
                                    echo '<img src="img/masque.png" alt="Masqu&eacute;" class="imgtitlenews" />';
                                }
                            } else {
                                echo '<img src="img/n_modere.png" alt="Non mod&eacute;r&eacute;" class="imgtitlenews" />';
                            }
                        }
                        // Catégories avec images
                        echo '
						<img src="img/placeholder_100x100.gif" alt="icon" class="avatar bordered"/>
						';
                        // Votes
                        if ($privileges > 2) {
                            echo '<span class="vote">';
                            if ($per_vote > 0) {
                                echo '<a href="?action=vote_post&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="img/bright_votepro.png" alt="+1" class="imgvote" /></a>';
                            } else {
                                if ($vote_filt) {
                                    echo '<a href="?action=vote_post&amp;order=1&amp;thread_id=' . $thread_id_affiche . '"><img src="img/pale_votepro.png" alt="+1" class="imgvote" /></a>';
                                } else {
                                    echo '<a href="?action=vote_post&amp;order=1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="img/pale_votepro.png" alt="+1" class="imgvote" /></a>';
                                }
                            }
                            if ($per_vote < 0) {
                                echo '<a href="?action=vote_post&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="img/bright_voteneg.png" alt="-1" class="imgvote" /></a>';
                            } else {
                                if ($vote_filt) {
                                    echo '<a href="?action=vote_post&amp;order=-1&amp;thread_id=' . $thread_id_affiche . '"><img src="img/pale_voteneg.png" alt="-1" class="imgvote" /></a>';
                                } else {
                                    echo '<a href="?action=vote_post&amp;order=-1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '"><img src="img/pale_voteneg.png" alt="-1" class="imgvote" /></a>';
                                }
                            }
                            echo '</span>';
                        }
                        //close-open columns
                        echo '
						    </div>
						    <div class="span6">';
                        //add gravatar
                        echo '
						       <header class="row">
							  <div class="span1">
							     <img src="img/placeholder_50x50.gif" alt="icon" class="avatar bordered"/>
							  </div>
						';
                        //start meta
                        echo '
							 <div class="span5">
							  <p class="meta">
							   <small>
							   Posted by :
						';
                        // name + link to profile
                        if (!empty($row["possibly_name"])) {
                            echo '<a href="#">' . htmlentities($row["possibly_name"]) . '</a>';
                        }
                        // tags
                        echo '
							with tags : <a href="#">' . htmlentities($row["category_name"]) . '</a>';
                        //close meta
                        echo '
						</small>
						  </p>';
                        // Titre
                        echo '
						<h3>' . htmlentities(stripslashes($row["title"])) . '</h3>';
                        //share sns buttons + close header
                        echo '
						  <section class="sns"><!-- AddThis Button BEGIN -->
							<div class="addthis_toolbox addthis_default_style ">
							<a class="addthis_button_preferred_1"></a>
							<a class="addthis_button_preferred_2"></a>
							<a class="addthis_button_preferred_3"></a>
							</div>
							<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4f3e39a4223675c7"></script>
						  </section><!-- AddThis Button END -->
						</div><!--span5 -->
					       </header>
					       ';
                        /*
                        echo('
                        <div class="votebar">');
                        
                        // Etat des votes
                        if ($pro_vote==0)
                        {
                        	if($agt_vote==0)
                        	{
                        		echo('<span class="neutralvote">
                        				<span class="votebarannotation">
                        					+0
                        				</span>
                        			</span>
                        		</div>');
                        	}
                        	else
                        	{
                        		echo('<span class="againstvote" style="height:100%;width:8px;">
                        				<span class="votebarannotation">
                        					-'.htmlentities($agt_vote).'
                        				</span>
                        			</span>
                        		</div>');
                        	}
                        }
                        else
                        {
                        	if($agt_vote==0)
                        	{
                        		echo('<span class="provote" style="height:100%;width:8px;">
                        				<span class="votebarannotation_pro">
                        					+'.htmlentities($pro_vote).'
                        				</span>
                        			</span>
                        		</div>');
                        	}
                        	else
                        	{
                        		$prop_pro=round(100*$pro_vote/($agt_vote+$pro_vote));
                        		echo('<span class="provote" style="height:'.$prop_pro.'%;width:8px;">
                        				<span class="votebarannotation_pro">
                        					+'.htmlentities($pro_vote).'
                        				</span>
                        			</span>
                        			<span class="againstvote" style="height:'.(100-$prop_pro).'%;width:8px;">
                        				<span class="votebarannotation">
                        					-'.htmlentities($agt_vote).'
                        				</span>
                        			</span>
                        		</div>');
                        	}
                        }
                        */
                        // Corps du texte
                        echo '<div class="content"><p>' . text_display_prepare($row["text"]) . '</p></div>';
                        // utils
                        echo '<footer class="">';
                        //upvote
                        echo '<a class="" href="?action=vote_post&amp;order=' . '1' . '&amp;thread_id=' . $thread_id_affiche . '">' . _('Upvote') . '<i class="icon-thumbs-up"></i>' . '</a>';
                        echo " - ";
                        // downvote
                        echo '<a class="" href="?action=vote_post&amp;order=' . '-1' . '&amp;thread_id=' . $thread_id_affiche . '">' . _('Downvote') . '<i class="icon-thumbs-down"></i>' . '</a>';
                        echo " - ";
                        // Date
                        echo '<time class="" datetime="' . htmlentities(transfo_date($row["date"])) . '">' . htmlentities(transfo_date($row["date"])) . '</time>';
                        echo " - ";
                        // comments
                        affichage_comments($thread_id, false);
                        // utils delete/edite/anonymize
                        if ($is_proprio || $privileges > 4) {
                            echo ' | 
								<a class="adminutil" href="?action=edit_post&amp;thread_id=' . $thread_id_affiche . '">' . _('Edit') . '</a>
								 - 
								<a class="adminutil" href="?action=remove_post&amp;thread_id=' . $thread_id_affiche . '">' . _('Delete') . '</a>';
                            // hide name
                            if ($is_proprio) {
                                if (!empty($row["possibly_name"])) {
                                    echo ' - <a href="?action=anonymization&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">' . _('Hide my name') . '</a>';
                                } else {
                                    echo ' - <a href="?action=anonymization&amp;order=1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">' . _('Show my name') . '</a>';
                                }
                            }
                        }
                        if ($is_admin) {
                            if ($is_valid || !$already_mod) {
                                if ($current_mod) {
                                    echo '<a href="?action=moderation&amp;order=0&amp;thread_id=' . $thread_id_affiche . '">Refuser</a>';
                                } else {
                                    echo '<a href="?action=moderation&amp;order=0&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">Refuser</a>';
                                }
                            }
                            if (!$is_valid || !$already_mod) {
                                if ($current_mod) {
                                    echo '<a href="?action=moderation&amp;order=1&amp;thread_id=' . $thread_id_affiche . '">Accepter</a>';
                                } else {
                                    echo '<a href="?action=moderation&amp;order=1&amp;thread_id=' . $thread_id_affiche . '#' . $thread_id_affiche . '">Accepter</a>';
                                }
                            }
                        }
                        echo '</small></footer>';
                        // COMMENTS
                        echo '<div class="commentbox">
					
					<article class="comment clearfix">
						<header class="span1">
							<img src="img/placeholder_50x50.gif" alt="icon" class="avatar bordered"/>
						</header>
						<div class="com-content span4">
						Lorem Ipsum
						</div>
						<footer>';
                        //upvote
                        echo '<a class="" href="?action=vote_post&amp;order=' . '1' . '&amp;thread_id=' . $thread_id_affiche . '">' . _('Upvote') . '<i class="icon-thumbs-up"></i>' . '</a>';
                        echo " - ";
                        // downvote
                        echo '<a class="" href="?action=vote_post&amp;order=' . '-1' . '&amp;thread_id=' . $thread_id_affiche . '">' . _('Downvote') . '<i class="icon-thumbs-down"></i>' . '</a>';
                        echo " - ";
                        // timestamp
                        echo '<time datetime="2010-12-16T11:15Z">16/12/2010 11:15</time>
						</footer>

					</article>
					
					</div><!-- .commentbox-->
					</article><!-- .feeditem -->';
                    }
                }
                // Affichage vide / d'un cadre de choix de page / d'un avertissement sur le nombre de résultats / selon les cas
                if ($result_returned) {
                    echo $change_page . '<div class="newsterminator"><hr />' . NOM_ECOLE . ' REFRESH</div>';
                } else {
                    echo '<div class="warning">Aucune proposition n\'est disponible selon les critères choisis</div>';
                }
                @mysql_free_result($result);
            } else {
                echo '<div class="warning">Erreur lors de la requ&ecirc;te</div>';
            }
        }
    } else {
        need_ecole_member_privilege(2);
    }
}
コード例 #4
0
ファイル: actions.php プロジェクト: AnthonyReese/Refresh
/**
 * deletes a comment
 *   
 */
function delete_comment($comment_id, $privileges, $login, $output = '')
{
    $priv = $privileges;
    if ($priv > 2) {
        echo '<h1>Suppression :</h1>';
        if (is_numeric($comment_id) && $comment_id > 0) {
            $result = @mysql_query(sprintf("SELECT comment_id,text,rand_prop,hash_prop FROM comment WHERE comment_id='%s'", mysql_real_escape_string($comment_id)));
            if (!$result || mysql_num_rows($result) < 1) {
                $warnings = '<div class="warning">Commentaire inexistant</div>';
            } else {
                $row = mysql_fetch_assoc($result);
                $id = $row["comment_id"];
                $mess_user = trim($row["text"]);
                $is_prop = check_property($row["rand_prop"], $row["hash_prop"]);
                @mysql_free_result($result);
            }
        } else {
            $warnings = '<div class="warning">Commentaire inexistant</div>';
        }
        if (empty($warnings) && $id > 0) {
            if (isset($_SESSION['post'])) {
                $_POST = $_SESSION['post'];
                unset($_SESSION['post']);
            }
            // Traitement d'un formulaire éventuellement déjà validé
            $affich_form = true;
            if (isset($_POST['form_name']) && $_POST['form_name'] == "deletion") {
                if (!isset($_POST["validation"])) {
                    echo '<div class="warning">Vous n\'avez pas confirm&eacute; la suppression</div>';
                } elseif ($_POST["validation"] == "on") {
                    if ($priv > 4 || $is_prop == 1) {
                        if (@mysql_query(sprintf("DELETE FROM comment WHERE comment_id='%s'", mysql_real_escape_string($id)))) {
                            echo '<div class="success">Commentaire correctement supprim&eacute;</div>';
                            $affich_form = false;
                        } else {
                            echo '<div class="warning">Erreur lors de la suppression du commentaire</div>';
                        }
                    } else {
                        echo '<div class="warning">Vous ne disposez pas des droits n&eacute;cessaires</div>';
                    }
                }
            }
            // Affichage du formulaire le cas échéant
            if ($affich_form) {
                if ($priv > 4 || $is_prop == 1) {
                    echo '<form method="post" action="?action=remove_post&comment_id=' . htmlentities($id) . '">';
                    echo 'Souhaitez-vous r&eacute;ellement supprimer le commentaire suivant ?<br />"';
                    echo nl2br(htmlentities(stripslashes($mess_user))) . '"<br /><br />';
                    echo '<input type="checkbox" name="validation" id="v_check" /><label for="v_check">Oui, supprimer !</label>';
                    echo '<input type="hidden" name="form_name" value="deletion" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="Valider" /></form>';
                } else {
                    echo '<div class="warning">Vous ne disposez pas des droits n&eacute;cessaires</div>';
                }
            }
        } elseif (!empty($warnings)) {
            echo $warnings;
        }
        if (isset($_POST)) {
            unset($_POST);
        }
    } else {
        need_logged_member_privilege();
    }
}
コード例 #5
0
ファイル: comments.php プロジェクト: AnthonyReese/Refresh
function affichage_comments($thread_id, $moderation_mode = false, $unique_mode = false)
{
    $privileges = user_privilege_level();
    $is_admin = $privileges > 3;
    $is_logged = is_logged();
    $ancre = htmlentities($thread_id);
    if ($moderation_mode) {
        if ($is_admin) {
            $escaped_name = mysql_real_escape_string($_SESSION['login_c']);
            $comments = get_comments($thread_id, $privileges, $escaped_name, $output = '');
            if ($comments->result) {
                $result_returned = false;
                foreach ($comments->data as $thread_id => $row) {
                    $result_returned = true;
                    $is_proprio = check_property($row["rand_prop"], $row["hash_prop"]);
                    $ancre = htmlentities($row["comment_id"]);
                    $date = $row['date'];
                    $possibly_name = $row['possibly_name'];
                    $sec_cid = htmlentities($row["comment_id"]);
                    $thread_tmp = htmlentities($row["thread_id"]);
                    $text = text_display_prepare(trim($row["text"]));
                    // Informations de contexte
                    display_comment($row, True, $privileges, $is_admin, $unique_mode);
                }
                if (!$result_returned) {
                    echo '<div class="warning">Aucun commentaire n\'est disponible selon les critères choisis</div>';
                }
            } else {
                echo '<div class="warning">Erreur lors de la recherche des commentaires non mod&eacute;r&eacute;s</div>';
            }
        } else {
            echo '<div class="warning">Vous ne disposez pas des droits n&eacute;cessaires</div>';
        }
    } else {
        if ($privileges > 1) {
            if (isset($_SESSION["unroll_comment"]) && $_SESSION["unroll_comment"] == $thread_id) {
                $escaped_threadid = mysql_real_escape_string($thread_id);
                $escaped_name = isset($_SESSION['login_c']) ? mysql_real_escape_string($_SESSION['login_c']) : '';
                $comments = get_comments($escaped_threadid, $privileges, $escaped_name, $output = '');
                if ($comments->result) {
                    if ($privileges > 3) {
                        $result_temp = @mysql_query(sprintf("SELECT COUNT(*) AS NB_COMMENT FROM comment WHERE thread_id='%s'", mysql_real_escape_string($thread_id)));
                    } else {
                        if ($is_logged) {
                            $result_temp = @mysql_query(sprintf("SELECT COUNT(*) AS NB_COMMENT FROM comment WHERE thread_id='%s' AND (is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($thread_id), mysql_real_escape_string($_SESSION['login_c'])));
                        } else {
                            $result_temp = @mysql_query(sprintf("SELECT COUNT(*) AS NB_COMMENT FROM comment WHERE is_valid=1 AND thread_id='%s'", mysql_real_escape_string($thread_id)));
                        }
                    }
                    if ($row = mysql_fetch_assoc($result_temp)) {
                        $nb_comment = htmlentities($row["NB_COMMENT"]);
                        display_speccom($unique_mode, $ancre, $thread_id, $nb_comment, 'roll');
                    }
                    @mysql_free_result($result_temp);
                    foreach ($comments->data as $thread_id => $row) {
                        $is_proprio = check_property($row["rand_prop"], $row["hash_prop"]);
                        $is_valid = $row["is_valid"];
                        if ($is_valid || $is_proprio || $privileges > 3) {
                            // afficher les commentaires
                            display_comment($row, $is_logged, $privileges, $unique_mode);
                        }
                    }
                    $text_prec = "";
                    $anon_prec = "";
                    if (isset($_SESSION["text_new_comment_rest"])) {
                        $text_prec = $_SESSION["text_new_comment_rest"];
                    }
                    if (isset($_SESSION["text_anonymous_rest"])) {
                        $anon_prec = 1;
                    }
                    if ($privileges > 2) {
                        // display the form that allows users to post comments
                        display_comment_form($unique_mode, $ancre, $thread_id, $text_prec, $anon_prec);
                    }
                    if (isset($_SESSION["text_new_comment_rest"])) {
                        unset($_SESSION["text_new_comment_rest"]);
                    }
                    if (isset($_SESSION["text_anonymous_rest"])) {
                        unset($_SESSION["text_anonymous_rest"]);
                    }
                } else {
                    echo '<div class="warning">Erreur lors de la recherche des commentaires</div></div>';
                }
            } else {
                if ($privileges > 3) {
                    $result = @mysql_query(sprintf("SELECT COUNT(*) AS NB_COMMENT FROM comment WHERE thread_id='%s'", mysql_real_escape_string($thread_id)));
                } else {
                    if (is_logged()) {
                        $result = @mysql_query(sprintf("SELECT COUNT(*) AS NB_COMMENT FROM comment WHERE thread_id='%s' AND (is_valid=1 OR (CAST(SHA1(CONCAT('%s',CAST(rand_prop AS CHAR))) AS CHAR)=hash_prop))", mysql_real_escape_string($thread_id), mysql_real_escape_string($_SESSION['login_c'])));
                    } else {
                        $result = @mysql_query(sprintf("SELECT COUNT(*) AS NB_COMMENT FROM comment WHERE is_valid=1 AND thread_id='%s'", mysql_real_escape_string($thread_id)));
                    }
                }
                if ($result && ($row = mysql_fetch_assoc($result))) {
                    $nb_comment = htmlentities($row["NB_COMMENT"]);
                    display_speccom($unique_mode, $ancre, $thread_id, $nb_comment, 'unroll');
                } else {
                    echo '<div class="warning">Erreur lors de la recherche des commentaires</div></div>';
                }
                @mysql_free_result($result);
            }
        } else {
            echo '<div class="warning">Vous ne disposez pas des droits n&eacute;cessaires</div>';
        }
    }
}
コード例 #6
0
ファイル: os_app.php プロジェクト: jinguanio/david
function mod_app($app_name, $app_version, $json)
{
    $data = json_decode($json, true);
    if (!$data) {
        error_exit("invalid json:\n{$json}");
    }
    $os_app = new em_os_app();
    if (!isset($app_version)) {
        $condition = em_condition::factory('os:app', 'app:find_app');
        $condition->set_prefix(em_os::PREFIX_APP);
        $condition->set_columns(array('version'));
        $condition->set_eq('app', $app_name);
        $tmp = $os_app->find_app($condition);
        if (!$tmp) {
            error_exit('Not Found.');
        }
        if (1 != count($tmp)) {
            error_exit('Found ' . count($tmp) . ' record for `' . $app_name . '`');
        }
        $app_version = $tmp[0]['version'];
    }
    $trans = new em_transaction();
    $trans->begin();
    $app_property = em_os::property_factory('app', $data);
    check_property($app_property);
    $os_app->get_operator('app')->mod_app_by_name($app_name, $app_version, $app_property);
    $app_info = $os_app->get_operator('app')->fetch_app_by_name($app_name, $app_version);
    $os_app_id = $app_info['os_app_id'];
    $app_property->set_os_app_id($os_app_id);
    foreach (array('win', 'link', 'action') as $type) {
        if (!isset($data[$type])) {
            continue;
        }
        if (!is_array($data[$type])) {
            error_exit("invalid `{$type}` data:\n" . $data[$type]);
        }
        foreach ($data[$type] as $name => $attributes) {
            if (!is_numeric($name) && isset($attributes[$type])) {
                $name = $attributes[$type];
            }
            unset($attributes[$type]);
            $property = em_os::property_factory("app_{$type}", $attributes);
            $property->set_app($app_property);
            check_property($property);
            if (isset($app_info[$type][$name])) {
                $os_app->get_operator("app_{$type}")->{"mod_app_{$type}_by_name"}($os_app_id, $name, $property);
                unset($app_info[$type][$name]);
            } else {
                $property->{"set_{$type}"}($name);
                $os_app->get_operator("app_{$type}")->{"add_app_{$type}"}($property);
            }
        }
    }
    foreach (array('win', 'link', 'action') as $type) {
        if (empty($app_info[$type])) {
            continue;
        }
        $os_app->get_operator("app_{$type}")->{"del_app_{$type}_by_id"}($os_app_id, $app_info[$type]);
    }
    $trans->commit();
    echo "+OK\n";
    exit(0);
}