Exemple #1
0
switch ($_POST['type']) {
    case "initialize_export_table":
        DB::query("TRUNCATE TABLE " . prefix_table("export"));
        break;
        //CASE export to PDF format
    //CASE export to PDF format
    case "export_to_pdf_format":
        /*
        $ids = explode(',', $_POST['ids']);
        foreach ($ids as $id) {
        */
        $id = $_POST['id'];
        if (!in_array($id, $_SESSION['forbiden_pfs']) && in_array($id, $_SESSION['groupes_visibles'])) {
            // get path
            $tree->rebuild();
            $folders = $tree->getPath($id, true);
            $path = "";
            foreach ($folders as $val) {
                if ($path) {
                    $path .= " » ";
                }
                $path .= $val->title;
            }
            // send query
            $rows = DB::query("SELECT i.id as id, i.restricted_to as restricted_to, i.perso as perso, i.label as label, i.description as description, i.pw as pw, i.login as login,\n                    l.date as date, i.pw_iv as pw_iv,\n                    n.renewal_period as renewal_period\n                    FROM " . prefix_table("items") . " as i\n                    INNER JOIN " . prefix_table("nested_tree") . " as n ON (i.id_tree = n.id)\n                    INNER JOIN " . prefix_table("log_items") . " as l ON (i.id = l.id_item)\n                    WHERE i.inactif = %i\n                    AND i.id_tree= %i\n                    AND (l.action = %s OR (l.action = %s AND l.raison LIKE %s))\n                    ORDER BY i.label ASC, l.date DESC", "0", intval($id), "at_creation", "at_modification", "at_pw :%");
            $id_managed = '';
            $i = 0;
            $items_id_list = array();
            foreach ($rows as $record) {
                $restricted_users_array = explode(';', $record['restricted_to']);
                //exclude all results except the first one returned by query
/**
 * updateCacheTable()
 *
 * Update the CACHE table
 */
function updateCacheTable($action, $id = "")
{
    global $db, $server, $user, $pass, $database, $pre, $port, $encoding;
    require_once $_SESSION['settings']['cpassman_dir'] . '/sources/SplClassLoader.php';
    //Connect to DB
    require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Database/Meekrodb/db.class.php';
    DB::$host = $server;
    DB::$user = $user;
    DB::$password = $pass;
    DB::$dbName = $database;
    DB::$port = $port;
    DB::$encoding = $encoding;
    DB::$error_handler = 'db_error_handler';
    $link = mysqli_connect($server, $user, $pass, $database, $port);
    $link->set_charset($encoding);
    //Load Tree
    $tree = new SplClassLoader('Tree\\NestedTree', '../includes/libraries');
    $tree->register();
    $tree = new Tree\NestedTree\NestedTree(prefix_table("nested_tree"), 'id', 'parent_id', 'title');
    // Rebuild full cache table
    if ($action == "reload") {
        // truncate table
        DB::query("TRUNCATE TABLE " . $pre . "cache");
        // reload date
        $rows = DB::query("SELECT *\n            FROM " . $pre . "items as i\n            INNER JOIN " . $pre . "log_items as l ON (l.id_item = i.id)\n            AND l.action = %s\n            AND i.inactif = %i", 'at_creation', 0);
        foreach ($rows as $record) {
            // Get all TAGS
            $tags = "";
            $itemTags = DB::query("SELECT tag FROM " . $pre . "tags WHERE item_id=%i", $record['id']);
            foreach ($itemTags as $itemTag) {
                if (!empty($itemTag['tag'])) {
                    $tags .= $itemTag['tag'] . " ";
                }
            }
            // form id_tree to full foldername
            $folder = "";
            $arbo = $tree->getPath($record['id_tree'], true);
            foreach ($arbo as $elem) {
                if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) {
                    $elem->title = $_SESSION['login'];
                }
                if (empty($folder)) {
                    $folder = stripslashes($elem->title);
                } else {
                    $folder .= " » " . stripslashes($elem->title);
                }
            }
            // store data
            DB::insert($pre . "cache", array('id' => $record['id'], 'label' => $record['label'], 'description' => $record['description'], 'tags' => $tags, 'id_tree' => $record['id_tree'], 'perso' => $record['perso'], 'restricted_to' => $record['restricted_to'], 'login' => $record['login'] == null ? "" : $record['login'], 'folder' => $folder, 'author' => $record['id_user']));
        }
        // UPDATE an item
    } elseif ($action == "update_value") {
        // get new value from db
        $data = DB::queryfirstrow("SELECT label, description, id_tree, perso, restricted_to, login\n            FROM " . $pre . "items\n            WHERE id=%i", $id);
        // Get all TAGS
        $tags = "";
        $itemTags = DB::query("SELECT tag FROM " . $pre . "tags WHERE item_id=%i", $id);
        foreach ($itemTags as $itemTag) {
            if (!empty($itemTag['tag'])) {
                $tags .= $itemTag['tag'] . " ";
            }
        }
        // form id_tree to full foldername
        $folder = "";
        $arbo = $tree->getPath($data['id_tree'], true);
        foreach ($arbo as $elem) {
            if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) {
                $elem->title = $_SESSION['login'];
            }
            if (empty($folder)) {
                $folder = stripslashes($elem->title);
            } else {
                $folder .= " » " . stripslashes($elem->title);
            }
        }
        // finaly update
        DB::update($pre . "cache", array('label' => $data['label'], 'description' => $data['description'], 'tags' => $tags, 'id_tree' => $data['id_tree'], 'perso' => $data['perso'], 'restricted_to' => $data['restricted_to'], 'login' => $data['login'], 'folder' => $folder, 'author' => $_SESSION['user_id']), "id = %i", $id);
        // ADD an item
    } elseif ($action == "add_value") {
        // get new value from db
        $data = DB::queryFirstRow("SELECT i.label, i.description, i.id_tree as id_tree, i.perso, i.restricted_to, i.id, i.login\n            FROM " . $pre . "items as i\n            INNER JOIN " . $pre . "log_items as l ON (l.id_item = i.id)\n            WHERE i.id = %i\n            AND l.action = %s", $id, 'at_creation');
        // Get all TAGS
        $tags = "";
        $itemTags = DB::query("SELECT tag FROM " . $pre . "tags WHERE item_id = %i", $id);
        foreach ($itemTags as $itemTag) {
            if (!empty($itemTag['tag'])) {
                $tags .= $itemTag['tag'] . " ";
            }
        }
        // form id_tree to full foldername
        $folder = "";
        $arbo = $tree->getPath($data['id_tree'], true);
        foreach ($arbo as $elem) {
            if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) {
                $elem->title = $_SESSION['login'];
            }
            if (empty($folder)) {
                $folder = stripslashes($elem->title);
            } else {
                $folder .= " » " . stripslashes($elem->title);
            }
        }
        // finaly update
        DB::insert($pre . "cache", array('id' => $data['id'], 'label' => $data['label'], 'description' => $data['description'], 'tags' => $tags, 'id_tree' => $data['id_tree'], 'perso' => $data['perso'], 'restricted_to' => $data['restricted_to'], 'login' => $data['login'], 'folder' => $folder, 'author' => $_SESSION['user_id']));
        // DELETE an item
    } elseif ($action == "delete_value") {
        DB::delete($pre . "cache", "id = %i", $id);
    }
}
Exemple #3
0
     $rows = mysqli_query($dbTmp, $sql);
     while ($reccord = mysqli_fetch_array($rows)) {
         //Get all TAGS
         $tags = "";
         $itemsRes = mysqli_query($dbTmp, "SELECT tag FROM " . $_SESSION['tbl_prefix'] . "tags\n                        WHERE item_id=" . $reccord['id']) or die(mysqli_error($dbTmp));
         $itemTags = mysqli_fetch_array($itemsRes);
         if (!empty($itemTags)) {
             foreach ($itemTags as $itemTag) {
                 if (!empty($itemTag['tag'])) {
                     $tags .= $itemTag['tag'] . " ";
                 }
             }
         }
         //form id_tree to full foldername
         $folder = "";
         $arbo = $tree->getPath($reccord['id_tree'], true);
         foreach ($arbo as $elem) {
             $folder .= htmlspecialchars(stripslashes($elem->title), ENT_QUOTES) . " > ";
         }
         //store data
         mysqli_query($dbTmp, "INSERT INTO " . $_SESSION['tbl_prefix'] . "cache\n                        VALUES (\n                        '" . $reccord['id'] . "',\n                        '" . $reccord['label'] . "',\n                        '" . $reccord['description'] . "',\n                        '" . $tags . "',\n                        '" . $reccord['id_tree'] . "',\n                        '" . $reccord['perso'] . "',\n                        '" . $reccord['restricted_to'] . "',\n                        '" . $reccord['login'] . "',\n                        '" . $folder . "',\n                        '" . $reccord['id_user'] . "',\n                        0\n                        )");
     }
     echo 'document.getElementById("tbl_7").innerHTML = ' . '"<img src=\\"images/tick.png\\">";';
 } else {
     echo 'document.getElementById("res_step4").innerHTML = ' . '"An error appears on table CACHE!";';
     echo 'document.getElementById("tbl_7").innerHTML = ' . '"<img src=\\"images/exclamation-red.png\\">";';
     echo 'document.getElementById("loader").style.display = "none";';
     mysqli_close($dbTmp);
     break;
 }
 /*
 /*
  * CASE
  * List items of a group
  */
 case 'lister_items_groupe':
     $arboHtml = $html = "";
     $folderIsPf = $showError = 0;
     $itemsIDList = $rights = $returnedData = array();
     // Build query limits
     if (empty($_POST['start'])) {
         $start = 0;
     } else {
         $start = $_POST['start'];
     }
     // Prepare tree
     $arbo = $tree->getPath($_POST['id'], true);
     foreach ($arbo as $elem) {
         if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) {
             $elem->title = $_SESSION['login'];
             $folderIsPf = 1;
         }
         $arboHtml_tmp = '<a id="path_elem_' . $elem->id . '"';
         if (in_array($elem->id, $_SESSION['groupes_visibles'])) {
             $arboHtml_tmp .= ' style="cursor:pointer;" onclick="ListerItems(' . $elem->id . ', \'\', 0)"';
         }
         if (strlen($elem->title) > 20) {
             $arboHtml_tmp .= '>' . substr(htmlspecialchars(stripslashes($elem->title), ENT_QUOTES), 0, 17) . "..." . '</a>';
         } else {
             $arboHtml_tmp .= '>' . htmlspecialchars(stripslashes($elem->title), ENT_QUOTES) . '</a>';
         }
         if (empty($arboHtml)) {