Ejemplo n.º 1
0
function main($argc, $argv)
{
    $p = new Player();
    if (get_entry($argc, $argv, $p) == FALSE) {
        aff_help();
        return;
    }
    enter_the_game($p);
}
Ejemplo n.º 2
0
function restore($db_a, $dir, $type = false)
{
    global $sag;
    if ($handle = opendir($dir)) {
        try {
            $sag->createDatabase($db_a);
        } catch (Exception $e) {
            echo $e->getMessage() . "DB:" . $db_a . "\n";
        }
        $sag->setDatabase($db_a);
        while (false !== ($entry = readdir($handle))) {
            if (".." == $entry || "." == $entry) {
                continue;
            }
            $obj1 = get_entry($db_a, "/" . $entry);
            $temp_rev = $obj1['res']->_rev;
            $obj2 = json_decode(file_get_contents($dir . $entry . '/' . $entry . '.json'));
            if (is_object($obj1)) {
                $obj = update_together($obj1['res'], $obj2, 'object');
            } else {
                $obj = $obj2;
            }
            $obj = object2array($obj);
            unset($obj['err']);
            unset($obj['_rev']);
            try {
                if (preg_match("/^_/", urldecode($entry))) {
                    echo $sag->put(urldecode($entry), $obj)->body->ok;
                } else {
                    echo $sag->put($entry, $obj)->body->ok;
                }
            } catch (Exception $e) {
                if ($type == 'update') {
                    $obj['_rev'] = $temp_rev;
                    $obj['views'] = $obj['views'] + 1;
                }
                try {
                    if (preg_match("/^_/", urldecode($entry))) {
                        echo $sag->put(urldecode($entry), $obj)->body->ok;
                    } else {
                        echo $sag->put($entry, $obj)->body->ok;
                    }
                } catch (Exception $e) {
                    echo $e->getMessage() . "DB:" . $db_a . " file:" . urlencode($entry) . "\n";
                }
            }
        }
    }
    return "restore file->db finished\n";
}
Ejemplo n.º 3
0
Archivo: index.php Proyecto: Abilis/SPD
//сортировка идет по дате последней правки
//Разбираем полученный массив. Подробнее в functions.php
$entries = $entries_arr[0];
$page = $entries_arr[1];
//текущая страница
$total = $entries_arr[2];
//всего страниц
//Если массив $_GET не пустой, то обработка правки и удаления записей
if ($_GET['action'] == 'edit') {
    //правка записи
    //если нет прав - редирект на главную
    if (!$canDoEdit) {
        header('Location: index.php');
        die;
    }
    $entry = get_entry($link, $_GET['id_entry']);
    //вытаскиваем конкретную запись из БД
    //Разбираем массив в переменные
    $id_entry = $entry['id_entry'];
    $numOrder = $entry['numOrder'];
    $customer = $entry['customer'];
    $tarif = $entry['tarif'];
    $ip_address = $entry['ip_address'];
    $netmask = $entry['netmask'];
    $gateway = $entry['gateway'];
    $vlan_id = $entry['vlan_id'];
    $customer_port = $entry['customer_port'];
    $termination_point = $entry['termination_point'];
    $commentary = $entry['commentary'];
    //Выводим в шаблоны
    include_once 'views/v-header.php';
Ejemplo n.º 4
0
function afficher_form_billet($article, $erreurs)
{
    function s_color($color)
    {
        return '<button type="button" onclick="insertTag(\'[color=' . $color . ']\',\'[/color]\',\'contenu\');"><span style="background:' . $color . ';"></span></button>';
    }
    function s_size($size)
    {
        return '<button type="button" onclick="insertTag(\'[size=' . $size . ']\',\'[/size]\',\'contenu\');"><span style="font-size:' . $size . 'pt;">' . $size . '. Ipsum</span></button>';
    }
    function s_u($char)
    {
        return '<button type="button" onclick="insertChar(\'' . $char . '\', \'contenu\');"><span>' . $char . '</span></button>';
    }
    if ($article != '') {
        $defaut_jour = $article['jour'];
        $defaut_mois = $article['mois'];
        $defaut_annee = $article['annee'];
        $defaut_heure = $article['heure'];
        $defaut_minutes = $article['minutes'];
        $defaut_secondes = $article['secondes'];
        $titredefaut = $article['bt_title'];
        // abstract : s’il est vide, il est regénéré à l’affichage, mais reste vide dans la BDD)
        $chapodefaut = get_entry($GLOBALS['db_handle'], 'articles', 'bt_abstract', $article['bt_id'], 'return');
        $notesdefaut = $article['bt_notes'];
        $categoriesdefaut = $article['bt_categories'];
        $contenudefaut = htmlspecialchars($article['bt_wiki_content']);
        $motsclesdefaut = $article['bt_keywords'];
        $statutdefaut = $article['bt_statut'];
        $allowcommentdefaut = $article['bt_allow_comments'];
    } else {
        $defaut_jour = date('d');
        $defaut_mois = date('m');
        $defaut_annee = date('Y');
        $defaut_heure = date('H');
        $defaut_minutes = date('i');
        $defaut_secondes = date('s');
        $chapodefaut = '';
        $contenudefaut = '';
        $motsclesdefaut = '';
        $categoriesdefaut = '';
        $titredefaut = '';
        $notesdefaut = '';
        $statutdefaut = '1';
        $allowcommentdefaut = '1';
    }
    if ($erreurs) {
        echo erreurs($erreurs);
    }
    if (isset($article['bt_id'])) {
        echo '<form id="form-ecrire" method="post" onsubmit="return moveTag();" action="' . $_SERVER['PHP_SELF'] . '?post_id=' . $article['bt_id'] . '" >' . "\n";
    } else {
        echo '<form id="form-ecrire" method="post" onsubmit="return moveTag();" action="' . $_SERVER['PHP_SELF'] . '" >' . "\n";
    }
    echo '<input id="titre" name="titre" type="text" size="50" value="' . $titredefaut . '" required="" placeholder="' . ucfirst($GLOBALS['lang']['placeholder_titre']) . '" tabindex="30" class="text" spellcheck="true" />' . "\n";
    echo '<div id="chapo_note">' . "\n";
    echo '<div id="blocchapo">' . "\n";
    echo '<textarea id="chapo" name="chapo" rows="5" cols="60" placeholder="' . ucfirst($GLOBALS['lang']['placeholder_chapo']) . '" tabindex="35" class="text" >' . $chapodefaut . '</textarea>' . "\n";
    echo '</div>' . "\n";
    echo '<div id="blocnote">' . "\n";
    echo '<textarea id="notes" name="notes" rows="5" cols="30" placeholder="' . ucfirst($GLOBALS['lang']['placeholder_notes']) . '" tabindex="40" class="text" >' . $notesdefaut . '</textarea>' . "\n";
    echo '</div>' . "\n";
    echo '</div>' . "\n";
    echo '<p class="formatbut">' . "\n";
    echo "\t" . '<button id="button01" class="but" type="button" title="' . $GLOBALS['lang']['bouton-gras'] . '" onclick="insertTag(\'[b]\',\'[/b]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button02" class="but" type="button" title="' . $GLOBALS['lang']['bouton-ital'] . '" onclick="insertTag(\'[i]\',\'[/i]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button03" class="but" type="button" title="' . $GLOBALS['lang']['bouton-soul'] . '" onclick="insertTag(\'[u]\',\'[/u]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button04" class="but" type="button" title="' . $GLOBALS['lang']['bouton-barr'] . '" onclick="insertTag(\'[s]\',\'[/s]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<span class="spacer"></span>' . "\n";
    // bouton des couleurs
    echo "\t" . '<span id="button13" class="but but-dropdown" title=""><span></span><span class="list list-color">' . s_color('black') . s_color('gray') . s_color('silver') . s_color('white') . s_color('blue') . s_color('green') . s_color('red') . s_color('yellow') . s_color('fuchsia') . s_color('lime') . s_color('aqua') . s_color('maroon') . s_color('purple') . s_color('navy') . s_color('teal') . s_color('olive') . s_color('#ff7000') . s_color('#ff9aff') . s_color('#a0f7ff') . s_color('#ffd700') . '</span></span>' . "\n";
    // boutons de la taille de caractère
    echo "\t" . '<span id="button14" class="but but-dropdown" title=""><span></span><span class="list list-size">' . s_size('9') . s_size('12') . s_size('16') . s_size('20') . '</span></span>' . "\n";
    // quelques caractères unicode
    echo "\t" . '<span id="button15" class="but but-dropdown" title=""><span></span><span class="list list-spechr">' . s_u('æ') . s_u('Æ') . s_u('œ') . s_u('Œ') . s_u('é') . s_u('É') . s_u('è') . s_u('È') . s_u('ç') . s_u('Ç') . s_u('ù') . s_u('Ù') . s_u('à') . s_u('À') . s_u('ö') . s_u('Ö') . s_u('…') . s_u('«') . s_u('»') . s_u('±') . s_u('≠') . s_u('×') . s_u('÷') . s_u('ß') . s_u('®') . s_u('©') . s_u('↓') . s_u('↑') . s_u('←') . s_u('→') . s_u('ø') . s_u('Ø') . s_u('☠') . s_u('☣') . s_u('☢') . s_u('☮') . s_u('★') . s_u('☯') . s_u('☑') . s_u('☒') . s_u('☐') . s_u('♫') . s_u('♬') . s_u('♪') . s_u('♣') . s_u('♠') . s_u('♦') . s_u('❤') . s_u('♂') . s_u('♀') . s_u('☹') . s_u('☺') . s_u('☻') . s_u('♲') . s_u('⚐') . s_u('⚠') . s_u('☂') . s_u('√') . s_u('∑') . s_u('λ') . s_u('π') . s_u('Ω') . s_u('№') . s_u('∞') . '</span></span>' . "\n";
    echo "\t" . '<span class="spacer"></span>' . "\n";
    echo "\t" . '<button id="button05" class="but" type="button" title="' . $GLOBALS['lang']['bouton-left'] . '" onclick="insertTag(\'[left]\',\'[/left]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button06" class="but" type="button" title="' . $GLOBALS['lang']['bouton-center'] . '" onclick="insertTag(\'[center]\',\'[/center]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button07" class="but" type="button" title="' . $GLOBALS['lang']['bouton-right'] . '" onclick="insertTag(\'[right]\',\'[/right]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button08" class="but" type="button" title="' . $GLOBALS['lang']['bouton-justify'] . '" onclick="insertTag(\'[justify]\',\'[/justify]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<span class="spacer"></span>' . "\n";
    echo "\t" . '<button id="button09" class="but" type="button" title="' . $GLOBALS['lang']['bouton-lien'] . '" onclick="insertTag(\'[\',\'|http://]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button10" class="but" type="button" title="' . $GLOBALS['lang']['bouton-cita'] . '" onclick="insertTag(\'[quote]\',\'[/quote]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button11" class="but" type="button" title="' . $GLOBALS['lang']['bouton-imag'] . '" onclick="insertTag(\'[img]\',\'|alt[/img]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button12" class="but" type="button" title="' . $GLOBALS['lang']['bouton-code'] . '" onclick="insertTag(\'[code]\',\'[/code]\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<span class="spacer"></span>' . "\n";
    echo "\t" . '<button id="button16" class="but" type="button" title="' . $GLOBALS['lang']['bouton-liul'] . '" onclick="insertChar(\'\\n\\n** element 1\\n** element 2\\n\',\'contenu\');"><span></span></button>' . "\n";
    echo "\t" . '<button id="button17" class="but" type="button" title="' . $GLOBALS['lang']['bouton-liol'] . '" onclick="insertChar(\'\\n\\n## element 1\\n## element 2\\n\',\'contenu\');"><span></span></button>' . "\n";
    echo '</p>';
    echo '<textarea id="contenu" name="contenu" rows="20" cols="60" required="" placeholder="' . ucfirst($GLOBALS['lang']['placeholder_contenu']) . '" tabindex="55" class="text">' . $contenudefaut . '</textarea>' . "\n";
    echo form_categories_links('articles', $categoriesdefaut);
    echo "\t" . '<input list="htmlListTags" type="text" class="text" id="type_tags" name="tags" onkeydown="chkHit(event);" placeholder="' . ucfirst($GLOBALS['lang']['placeholder_tags']) . '" tabindex="65"/>' . "\n";
    echo "\t" . '<input type="hidden" id="categories" name="categories" value="" />' . "\n";
    if ($GLOBALS['automatic_keywords'] == '0') {
        echo '<div><input id="mots_cles" name="mots_cles" type="text" size="50" value="' . $motsclesdefaut . '" placeholder="' . ucfirst($GLOBALS['lang']['placeholder_motscle']) . '" tabindex="67" class="text" /></div>' . "\n";
    }
    echo '<div id="date-and-opts">' . "\n";
    echo '<div id="date">' . "\n";
    echo '<span id="formdate">' . "\n";
    form_annee($defaut_annee);
    form_mois($defaut_mois);
    form_jour($defaut_jour);
    echo '</span>' . "\n\n";
    echo '<span id="formheure">';
    form_heure($defaut_heure, $defaut_minutes, $defaut_secondes);
    echo '</span>' . "\n";
    echo '</div>' . "\n";
    echo '<div id="opts">' . "\n";
    echo '<span id="formstatut">' . "\n";
    form_statut($statutdefaut);
    echo '</span>' . "\n";
    echo '<span id="formallowcomment">' . "\n";
    form_allow_comment($allowcommentdefaut);
    echo '</span>' . "\n";
    echo '</div>' . "\n";
    echo '</div>' . "\n";
    echo '<p class="centrer">' . "\n";
    echo '<input class="submit blue-square" type="submit" name="enregistrer" onclick="contenuLoad=document.getElementById(\'contenu\').value" value="' . $GLOBALS['lang']['envoyer'] . '" tabindex="70" />' . "\n";
    if ($article) {
        echo '<input class="submit red-square" type="submit" name="supprimer" value="' . $GLOBALS['lang']['supprimer'] . '" onclick="contenuLoad = document.getElementById(\'contenu\').value; return window.confirm(\'' . $GLOBALS['lang']['question_suppr_article'] . '\')" />' . "\n";
        echo hidden_input('article_id', $article['bt_id']);
        echo hidden_input('article_date', $article['bt_date']);
        echo hidden_input('ID', $article['ID']);
    }
    echo '</p>' . "\n";
    echo hidden_input('_verif_envoi', '1');
    echo hidden_input('token', new_token());
    echo '</form>' . "\n";
}
Ejemplo n.º 5
0
function receiveFileFragments($F)
{
    extract($F);
    $filekey_valid = check_filekey_validity($filekey, $db);
    if ($filekey_valid) {
        #Get the information about the file from the table
        $file_id = get_entry("file_transfer", "file_id", "filekey", $filekey, $db);
        $filesize = get_entry("file_transfer", "filesize", "filekey", $filekey, $db);
        $originalname = get_entry("file_transfer", "filename", "filekey", $filekey, $db);
        #list($name, $extension) = explode('.', $originalname);
        ereg('([A-Za-z0-9]+)\\.*([A-Za-z0-9]*)$', $originalname, $tokens);
        $name = $tokens[1];
        $extension = $tokens[2];
        #$name = ereg_replace('.([A-Za-z0-9]*)$', '', $originalname);
        if ($fragNr == '') {
            $fragNr = $_REQUEST['fragNr'];
        }
        list($thisfrag, $totalfrag) = explode('/', $fragNr);
        #Define the folder where these files will be stored
        $folder = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'] . '/tmps3db/';
        $filename = $folder . $file_id . '_' . $thisfrag . '.tmp';
        $final = $folder . $file_id . '.' . $extension;
        if ($fileStr == '') {
            $fileStr = $_REQUEST['fileStr'];
        }
        #decode the fragment right after receiving them if they were encoded one at a time
        if ($_REQUEST['encode'] == '2') {
            $fileStr = base64_decode($fileStr);
        }
        $indname = $folder . 'ind' . $file_id . '.txt';
        $fid = fopen($filename, 'a+');
        chmod($filename, 0777);
        if ($fragNr == '' || $fileStr == '') {
            echo "<report>Syntax: <BR>";
            echo "&lt;filekey&gt;...&lt;/filekey&gt;<BR>";
            echo "&lt;fragNr&gt;[this frag]/[total nr of frags]&lt;/fragNr&gt;<BR>";
            echo "&lt;fileStr&gt;(hexadecimal encoded fragment string)&lt;/fileStr&gt;<BR>";
            echo "</report>";
        } else {
            if ($filesize != '' && filesize($filename) == $filesize) {
                echo "<report>This file was already uploaded</report>";
            } elseif ($thisfrag > $totalfrag) {
                echo "<report>Too many fragments</report>";
            } else {
                $F = compact('thisfrag', 'fileStr', 'totalfrag', 'fid', 'filename', 'indname', 'final');
                #echo '<pre>';print_r($F);
                echo put_the_frag_on_file($F);
                #echo $thisfrag.' out of'.$totalfrag;
                #When the last fragment is in, decode the entire file
                if ($thisfrag == $totalfrag) {
                    #find all the fragment files in the folder,  write them in the final file
                    for ($i = 1; $i <= $totalfrag; $i++) {
                        $fragment_file_name = $folder . $file_id . '_' . $i . '.tmp';
                        if (is_file($fragment_file_name)) {
                            if (file_put_contents($folder . $file_id . '.tmp', file_get_contents($fragment_file_name), FILE_APPEND)) {
                                unlink($fragment_file_name);
                            }
                        } else {
                            return "Fragment " . $i . " is missing, please upload it again.";
                            exit;
                        }
                    }
                    #decode the file in the end, if the user requested it
                    if ($_REQUEST['encode'] != '2') {
                        $fullStr = file_get_contents($folder . $file_id . '.tmp');
                        $decodedStr = base64_decode($fullStr);
                        if (!file_put_contents($folder . $file_id . '.tmp', $decodedStr)) {
                            echo "Failed accepting the file. Please try again or encode file one fragment at a time before sending.";
                            exit;
                        }
                    }
                    copy($folder . $file_id . '.tmp', $final);
                    chmod($final, 0777);
                    if (is_file($folder . $file_id . '.tmp')) {
                        unlink($folder . $file_id . '.tmp');
                    }
                    return "<report>Upload Complete</report>";
                } else {
                    fclose($fid);
                }
            }
        }
    }
}
Ejemplo n.º 6
0
function afficher_form_commentaire($article_id, $mode, $erreurs = '', $comm_id = '')
{
    $GLOBALS['form_commentaire'] = '';
    $p_auteur = isset($_POST['auteur']) ? protect($_POST['auteur']) : '';
    $p_email = isset($_POST['email']) ? protect($_POST['email']) : '';
    $p_webpage = isset($_POST['webpage']) ? protect($_POST['webpage']) : '';
    $p_comm = isset($_POST['commentaire']) ? protect($_POST['commentaire']) : '';
    if (isset($_POST['_verif_envoi']) and !empty($erreurs)) {
        $GLOBALS['form_commentaire'] = '<div id="erreurs"><strong>' . $GLOBALS['lang']['erreurs'] . '</strong> :' . "\n";
        $GLOBALS['form_commentaire'] .= '<ul><li>' . "\n";
        $GLOBALS['form_commentaire'] .= implode('</li><li>', $erreurs);
        $GLOBALS['form_commentaire'] .= '</li></ul></div>' . "\n";
        $defaut = array('auteur' => $p_auteur, 'email' => $p_email, 'webpage' => $p_webpage, 'commentaire' => $p_comm);
    } elseif (isset($mode) and $mode == 'admin') {
        if (empty($comm_id)) {
            $defaut = array('auteur' => $GLOBALS['auteur'], 'email' => $GLOBALS['email'], 'webpage' => $GLOBALS['racine'], 'commentaire' => '');
        } else {
            $actual_comment = $comm_id;
            $defaut = array('auteur' => protect($actual_comment['bt_author']), 'email' => protect($actual_comment['bt_email']), 'webpage' => protect($actual_comment['bt_webpage']), 'commentaire' => htmlspecialchars($actual_comment['bt_wiki_content']), 'status' => protect($actual_comment['bt_statut']));
        }
    } elseif (isset($_POST['previsualiser'])) {
        // parses the comment, but does not save it in a file
        $defaut = array('auteur' => $p_auteur, 'email' => $p_email, 'webpage' => $p_webpage, 'commentaire' => $p_comm);
        $comm['bt_content'] = formatage_commentaires($p_comm);
        $comm['bt_id'] = date('YmdHis');
        $comm['bt_author'] = $p_auteur;
        $comm['bt_email'] = $p_email;
        $comm['bt_webpage'] = $p_webpage;
        $comm['anchor'] = article_anchor($comm['bt_id']);
        $comm['bt_link'] = '';
        $comm['auteur_lien'] = $comm['bt_webpage'] != '' ? '<a href="' . $comm['bt_webpage'] . '" class="webpage">' . $comm['bt_author'] . '</a>' : $comm['bt_author'];
        $GLOBALS['form_commentaire'] .= '<div id="erreurs"><ul><li>Prévisualisation&nbsp;:</li></ul></div>' . "\n";
        $GLOBALS['form_commentaire'] .= '<div id="previsualisation">' . "\n";
        $GLOBALS['form_commentaire'] .= conversions_theme_commentaire(file_get_contents($GLOBALS['theme_post_comm']), $comm);
        $GLOBALS['form_commentaire'] .= '</div>' . "\n";
    } else {
        if (isset($_POST['_verif_envoi'])) {
            header('Location: ' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '#top');
            // redirection anti repostage;
        }
        $auteur_c = isset($_COOKIE['auteur_c']) ? protect($_COOKIE['auteur_c']) : '';
        $email_c = isset($_COOKIE['email_c']) ? protect($_COOKIE['email_c']) : '';
        $webpage_c = isset($_COOKIE['webpage_c']) ? protect($_COOKIE['webpage_c']) : '';
        $defaut = array('auteur' => $auteur_c, 'email' => $email_c, 'webpage' => $webpage_c, 'commentaire' => '', 'captcha' => '');
    }
    // prelim vars for Generation of comment Form
    $required = $GLOBALS['require_email'] == 1 ? 'required=""' : '';
    $cookie_checked = (isset($_COOKIE['cookie_c']) and $_COOKIE['cookie_c'] == 1) ? ' checked="checked"' : '';
    $subscribe_checked = (isset($_COOKIE['subscribe_c']) and $_COOKIE['subscribe_c'] == 1) ? ' checked="checked"' : '';
    // COMMENT FORM ON ADMIN SIDE : +always_open –captcha –previsualisation –verif
    if ($mode == 'admin') {
        $rand = substr(md5(rand(100, 999)), 0, 5);
        // begin with some additional stuff on comment "edit".
        if (isset($actual_comment)) {
            // edit
            $form = "\n" . '<form id="form-commentaire-' . $actual_comment['bt_id'] . '" class="form-commentaire" method="post" action="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '#erreurs">' . "\n";
            $form .= "\t" . '<div class="comm-edit-hidden-bloc">' . "\n";
            $form .= "\t" . '<fieldset class="syst">' . "\n";
            $form .= "\t\t" . hidden_input('is_it_edit', 'yes');
            $form .= "\t\t" . hidden_input('comment_id', $actual_comment['bt_id']);
            $form .= "\t\t" . hidden_input('status', $actual_comment['bt_statut']);
            $form .= "\t\t" . hidden_input('ID', $actual_comment['ID']);
            $form .= "\t\t" . hidden_input('token', $actual_comment['comm-token']);
            $form .= "\t" . '</fieldset><!--end syst-->' . "\n";
        } else {
            $form = "\n" . '<form id="form-commentaire" class="form-commentaire" method="post" action="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '#erreurs" >' . "\n";
        }
        $form .= "\t" . '<fieldset class="field">' . "\n";
        $form .= "\t\t" . hidden_input('comment_article_id', $article_id);
        $form .= "\t" . '<p class="formatbut">' . "\n";
        $form .= "\t\t" . '<button id="button01" class="but" type="button" title="' . $GLOBALS['lang']['bouton-gras'] . '" onclick="insertTag(\'[b]\',\'[/b]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button02" class="but" type="button" title="' . $GLOBALS['lang']['bouton-ital'] . '" onclick="insertTag(\'[i]\',\'[/i]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button03" class="but" type="button" title="' . $GLOBALS['lang']['bouton-soul'] . '" onclick="insertTag(\'[u]\',\'[/u]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button04" class="but" type="button" title="' . $GLOBALS['lang']['bouton-barr'] . '" onclick="insertTag(\'[s]\',\'[/s]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<span class="spacer"></span>' . "\n";
        $form .= "\t\t" . '<button id="button09" class="but" type="button" title="' . $GLOBALS['lang']['bouton-lien'] . '" onclick="insertTag(\'[\',\'|http://]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button10" class="but" type="button" title="' . $GLOBALS['lang']['bouton-cita'] . '" onclick="insertTag(\'[quote]\',\'[/quote]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button12" class="but" type="button" title="' . $GLOBALS['lang']['bouton-code'] . '" onclick="insertTag(\'[code]\',\'[/code]\',\'commentaire' . $rand . '\');"><span></span></button>' . "\n";
        $form .= "\t" . '</p><!--end formatbut-->' . "\n";
        $form .= "\t\t" . '<textarea class="commentaire text" name="commentaire" required="" placeholder="Lorem Ipsum" id="commentaire' . $rand . '" cols="50" rows="10">' . $defaut['commentaire'] . '</textarea>' . "\n";
        $form .= "\t" . '</fieldset>' . "\n";
        $form .= "\t" . '<fieldset class="infos">' . "\n";
        $form .= "\t\t" . '<label>' . $GLOBALS['lang']['label_dp_pseudo'] . '<input type="text" name="auteur" placeholder="John Doe" required="" value="' . $defaut['auteur'] . '" size="25" class="text" /></label>' . "\n";
        $form .= "\t\t" . '<label>' . ($GLOBALS['require_email'] == 1 ? $GLOBALS['lang']['label_dp_email_required'] : $GLOBALS['lang']['label_dp_email']) . '<input type="email" name="email" placeholder="*****@*****.**" ' . $required . ' value="' . $defaut['email'] . '" size="25" class="text" /></label>' . "\n";
        $form .= "\t\t" . '<label>' . $GLOBALS['lang']['label_dp_webpage'] . '<input type="url" name="webpage" placeholder="http://www.example.com" value="' . $defaut['webpage'] . '" size="25" class="text" /></label>' . "\n";
        $form .= "\t\t" . hidden_input('_verif_envoi', '1');
        $form .= "\t\t" . hidden_input('token', new_token());
        if (isset($actual_comment)) {
            // edit
            $checked = $actual_comment['bt_statut'] == '0' ? 'checked ' : '';
            $form .= "\t" . '<label>' . $GLOBALS['lang']['label_comm_priv'] . '<input type="checkbox" name="activer_comm" ' . $checked . '/></label>' . "\n";
            $form .= "\t" . '</fieldset><!--end info-->' . "\n";
            $form .= "\t" . '<fieldset class="buttons">' . "\n";
            $form .= "\t\t" . hidden_input('ID', $actual_comment['ID']);
            $form .= "\t\t" . '<p class="centrer"><input class="submit blue-square" type="submit" name="enregistrer" value="' . $GLOBALS['lang']['envoyer'] . '" /></p>' . "\n";
        } else {
            $form .= "\t" . '</fieldset><!--end info-->' . "\n";
            $form .= "\t" . '<fieldset class="buttons">' . "\n";
            $form .= "\t\t" . '<p class="centrer"><input class="submit blue-square" type="submit" name="enregistrer" value="' . $GLOBALS['lang']['envoyer'] . '" /></p>' . "\n";
        }
        $form .= "\t" . '</fieldset><!--end buttons-->' . "\n";
        $GLOBALS['form_commentaire'] .= $form;
        $GLOBALS['form_commentaire'] .= (isset($actual_comment) ? "\t" . '</div>' . "\n" : '') . '</form>' . "\n";
        // COMMENT ON PUBLIC SIDE
    } else {
        // Formulaire commun
        $form = "\n" . '<form id="form-commentaire" class="form-commentaire" method="post" action="' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '#erreurs" >' . "\n";
        $form .= "\t" . '<fieldset class="field">' . "\n";
        $form .= "\t" . '<p class="formatbut">' . "\n";
        $form .= "\t\t" . '<button id="button01" type="button" title="' . $GLOBALS['lang']['bouton-gras'] . '" onclick="insertTag(\'[b]\',\'[/b]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button02" type="button" title="' . $GLOBALS['lang']['bouton-ital'] . '" onclick="insertTag(\'[i]\',\'[/i]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button03" type="button" title="' . $GLOBALS['lang']['bouton-soul'] . '" onclick="insertTag(\'[u]\',\'[/u]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button04" type="button" title="' . $GLOBALS['lang']['bouton-barr'] . '" onclick="insertTag(\'[s]\',\'[/s]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<span class="spacer"></span>' . "\n";
        $form .= "\t\t" . '<button id="button09" type="button" title="' . $GLOBALS['lang']['bouton-lien'] . '" onclick="insertTag(\'[\',\'|http://]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button10" type="button" title="' . $GLOBALS['lang']['bouton-cita'] . '" onclick="insertTag(\'[quote]\',\'[/quote]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t\t" . '<button id="button12" type="button" title="' . $GLOBALS['lang']['bouton-code'] . '" onclick="insertTag(\'[code]\',\'[/code]\',\'commentaire\');"><span></span></button>' . "\n";
        $form .= "\t" . '</p><!--end formatbut-->' . "\n";
        $form .= "\t\t" . '<textarea class="commentaire" name="commentaire" required="" placeholder="' . $GLOBALS['lang']['label_commentaire'] . '" id="commentaire" cols="50" rows="10">' . $defaut['commentaire'] . '</textarea>' . "\n";
        $form .= "\t" . '</fieldset>' . "\n";
        $form .= "\t" . '<fieldset class="infos">' . "\n";
        $form .= "\t\t" . '<label>' . $GLOBALS['lang']['label_dp_pseudo'] . '<input type="text" name="auteur" placeholder="John Doe" required="" value="' . $defaut['auteur'] . '" size="25" class="text" /></label>' . "\n";
        $form .= "\t\t" . '<label>' . ($GLOBALS['require_email'] == 1 ? $GLOBALS['lang']['label_dp_email_required'] : $GLOBALS['lang']['label_dp_email']) . '<input type="email" name="email" placeholder="*****@*****.**" ' . $required . ' value="' . $defaut['email'] . '" size="25" /></label>' . "\n";
        $form .= "\t\t" . '<label>' . $GLOBALS['lang']['label_dp_webpage'] . '<input type="url" name="webpage" placeholder="http://www.example.com" value="' . $defaut['webpage'] . '" size="25" /></label>' . "\n";
        $form .= "\t\t" . '<label>' . $GLOBALS['lang']['label_dp_captcha'] . '<b>' . en_lettres($GLOBALS['captcha']['x']) . '</b> &#x0002B; <b>' . en_lettres($GLOBALS['captcha']['y']) . '</b> <input type="number" name="captcha" autocomplete="off" value="" class="text" /></label>' . "\n";
        $form .= "\t\t" . hidden_input('_token', $GLOBALS['captcha']['hash']);
        $form .= "\t\t" . hidden_input('_verif_envoi', '1');
        $form .= "\t" . '</fieldset><!--end info-->' . "\n";
        $form .= "\t" . '<fieldset class="cookie"><!--begin cookie asking -->' . "\n";
        $form .= "\t\t" . '<input class="check" type="checkbox" id="allowcookie" name="allowcookie"' . $cookie_checked . ' />' . label('allowcookie', $GLOBALS['lang']['comment_cookie']) . '<br/>' . "\n";
        $form .= "\t\t" . '<input class="check" type="checkbox" id="subscribe" name="subscribe"' . $subscribe_checked . ' />' . label('subscribe', $GLOBALS['lang']['comment_subscribe']) . "\n";
        $form .= "\t" . '</fieldset><!--end cookie asking-->' . "\n";
        $form .= "\t" . '<fieldset class="buttons">' . "\n";
        $form .= "\t\t" . '<input class="submit" type="submit" name="enregistrer" value="' . $GLOBALS['lang']['envoyer'] . '" />' . "\n";
        $form .= "\t\t" . '<input class="submit" type="submit" name="previsualiser" value="' . $GLOBALS['lang']['preview'] . '" />' . "\n";
        $form .= "\t" . '</fieldset><!--end buttons-->' . "\n";
        // ALLOW COMMENTS : ON
        if (get_entry($GLOBALS['db_handle'], 'articles', 'bt_allow_comments', $article_id, 'return') == '1' and $GLOBALS['global_com_rule'] == '0') {
            $GLOBALS['form_commentaire'] .= $form;
            if ($GLOBALS['comm_defaut_status'] == '0') {
                // petit message en cas de moderation a-priori
                $GLOBALS['form_commentaire'] .= "\t\t" . '<div class="need-validation">' . $GLOBALS['lang']['remarque'] . ' :' . "\n";
                $GLOBALS['form_commentaire'] .= "\t\t\t" . $GLOBALS['lang']['comment_need_validation'] . "\n";
                $GLOBALS['form_commentaire'] .= "\t\t" . '</div>' . "\n";
            }
            $GLOBALS['form_commentaire'] .= '</form>' . "\n";
        } else {
            $GLOBALS['form_commentaire'] .= '<p>' . $GLOBALS['lang']['comment_not_allowed'] . '</p>' . "\n";
        }
    }
}
Ejemplo n.º 7
0
            unset($local_entries[$id]);
        } else {
            // Local entry is newer, send it back
            $remote_index[$id] = $local_index[$id];
            $remote_entries[$id] = get_entry($id);
        }
    } else {
        $local_index[$id] = $remote_index[$id];
        store_entry($id, $_POST[$id]);
        unset($remote_entries[$id]);
    }
}
foreach ($diff_index as $id => $data) {
    //echo $data['timestamp'];
    if ($local_index[$id]['timestamp'] !== 0) {
        $remote_entries[$id] = get_entry($id);
        $remote_index[$id] = $local_index[$id];
    } else {
        unset($remote_entries[$id]);
        unset($remote_index[$id]);
    }
}
store_entry('_index', $local_index);
$return = array('index' => $remote_index, 'entries' => $remote_entries, 'debug' => $debug);
echo json_encode($return);
// Helpers
function get_entry($id)
{
    $file = DATA_DIR . '/' . $id;
    if (file_exists($file)) {
        if ($le = json_decode(file_get_contents($file), true)) {
Ejemplo n.º 8
0
function S3QLaction($s3ql)
{
    extract($s3ql);
    #grab a few relevant varuales
    $regexp = $GLOBALS['regexp'];
    $dbstruct = $GLOBALS['dbstruct'];
    #map a few vairables
    $s3map = $GLOBALS['s3map'];
    $format = $s3ql['format'];
    #Error messages
    extract($GLOBALS['messages']);
    #database and user identification
    if (!is_object($db)) {
        $db = $_SESSION['db'];
    }
    $key = $_REQUEST['key'] ? $_REQUEST['key'] : $s3ql['key'];
    $user_id = $user_id ? $user_id : $_SESSION['user']['account_id'];
    $user_info = s3info('users', $user_id, $db);
    if (!$user_id && !$db) {
        if (!$key) {
            return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'Please specify user_id and db or a key', $format, '');
        }
        #re-chekc if user provided is the same for key provided
    }
    $s3ql = array_diff_key($s3ql, array('db' => '', 'user_id' => ''));
    #take out from the array what needed to be included for wihitn S3DB queries
    if ($s3ql['update'] != '') {
        $s3ql['edit'] = $s3ql['update'];
        #update is closer to SQL, although original was edit. Must keep edit to be backward compatible
        $s3ql = array_filter(array_diff_key($s3ql, array('update' => 1)));
    }
    #identify the action
    $possible_actions = array('insert', 'edit', 'delete', 'select', 'update', 'grant');
    foreach ($possible_actions as $someaction) {
        if ($s3ql[$someaction] != '') {
            $action = $someaction;
        }
    }
    #if there is nothing as action, assume a select
    if ($action == '') {
        $action = 'select';
    }
    #identify the target
    if (ereg('(insert|edit|update|delete|grant)', $action)) {
        $s3ql['from'] = $s3ql[$action] == '' ? $_REQUEST[$action] : $s3ql[$action];
    } elseif (ereg('(select)', $action)) {
        $s3ql['from'] = $s3ql['from'] == '' ? $_REQUEST['from'] : $s3ql['from'];
    }
    #if there is no target, assume projects
    if ($s3ql['from'] == '') {
        $s3ql['from'] = 'projects';
    }
    if ($s3ql['from'] == 'permission') {
        $s3ql['from'] = 'user';
    }
    if ($s3ql['from'] == 'class') {
        $s3ql['from'] = 'collection';
    }
    if ($s3ql['from'] == 'instance') {
        $s3ql['from'] = 'item';
    }
    #these are targets ONLY for insert/edit/delete. Select takes plurals... was a bad idea, I know :-( but is much more intuitive :-)
    $possible_targets = array('permission', 'user', 'group', 'key', 'project', 'collection', 'item', 'rule', 'statement', 'filekey');
    #start taking action
    switch ($action) {
        case 'select':
            $data = selectQuery(compact('s3ql', 'db', 'user_id', 'format'));
            return $data;
            break;
            #Close select queries
        #Close select queries
        case 'insert':
            #echo '<pre>';print_r($s3ql);exit;
            #map s3ql input to s3db structure requirements
            if ($s3ql['insert'] == 'class') {
                $s3ql['insert'] = 'collection';
            }
            if ($s3ql['insert'] == 'instance') {
                $s3ql['insert'] = 'item';
            }
            if ($s3ql['where']['notes'] != '') {
                $s3ql['where']['notes'] = $s3ql['where']['notes'];
            }
            if ($s3ql['where']['value'] != '') {
                $s3ql['where']['value'] = $s3ql['where']['value'];
            }
            ##build inputs and oldvalues for validation and insert functions
            $tranformed = S3QLselectTransform(compact('s3ql', 'db', 'user_id'));
            $s3ql = $tranformed['s3ql'];
            $element = $s3ql['insert'];
            $element_id = $s3ql['where'][$element . '_id'];
            $letter = strtoupper(substr($element, 0, 1));
            $uid = $letter . $element_id;
            $required = array('key' => array(), 'project' => array('project_name'), 'collection' => array('project_id', 'entity'), 'rule' => array('project_id', 'subject_id', 'verb', 'object'), 'item' => array('collection_id'), 'statement' => array('item_id', 'rule_id', 'value'), 'file' => array('item_id', 'rule_id', 'filekey'), 'user' => array('account_lid', 'account_email'), 'group' => array('account_lid'));
            if (!in_array($element, array_keys($required))) {
                return formatReturn($GLOBALS['error_codes']['wrong_input'], $element . ' is not a valid S3DB element. Valid elements: key, project, collection, rule, item, statement, file', $format, '');
            }
            #if a subject is provided instead of a subject id in rule, dont break because of that. Find the subject
            #THIS PART NEEDS TO B HERE BECAUSE IT THE MANDATORY FIELDS ARE 'OR'
            if ($element == 'rule') {
                $s3ql = ruleInputsInfer($s3ql, $db, $user_id);
            }
            #echo '<pre>';print_r($s3ql);
            #translate some s3ql inputs into s3db names:
            #IS there anythi ng still missing? There are 2 types fo required inputs: thsoe from the user and those into the table. The firstare verified here, the rest are verified in "validation"
            $diff = array_diff($required[$element], array_keys($s3ql['where']));
            if ($element_id == '' && !empty($diff)) {
                return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide all the necessary fields: ' . rtrim(array_reduce($required[$element], "comma_split"), ", ") . '. ' . $syntax_message, $s3ql['format'], '');
            }
            #echo '<pre>';print_r($required[$element]);exit;
            #if there is any sort of id, check if user has permissions on that. In case of statement, permission must be checked on both rule and instance
            $inserteable = array('group' => 'group_id', 'user' => 'user_id', 'project' => 'project_id', 'rule' => 'rule_id', 'collection' => 'collection_id', 'item' => 'item_id', 'statement' => 'statement_id');
            #insert overal view
            #element_id is not empty
            #upstream resource provided
            #if all permissions clear up, grant permission to upper on loewer score;
            #upstream resource not provided
            #infer deployment if user, group or project, else nothing to do
            #element_id is empty
            #upstream resources provided
            #all permissions clear up, create new entry.
            #scoreTable will allow us to score the elements according to their position in the inheritance model. To nisert an "inserteable" A into an "inserteable" B,
            $scoreTable = array_reverse($inserteable, 0);
            $scoreTable = array_combine(array_keys($scoreTable), range(1, count($inserteable)));
            $elementScore = $scoreTable[$element];
            #check the score of target. All other score will be chacked against this one
            #for user, group and project, inserts occur in deployment (local). Except when there is indication on group or any other Id.
            $input_ids = array_intersect($inserteable, array_keys($s3ql['where']));
            if (ereg('^(U|G|P)$', $letter) && (count($input_ids) <= 1 || count(array_filter(array_diff_key($s3ql['where'], array($element . '_id' => '')))) == 0)) {
                $s3ql['where']['deployment_id'] = $s3ql['where']['deployment_id'] != '' ? $s3ql['where']['deployment_id'] : substr($GLOBALS['Did'], 1, strlen($GLOBALS['Did']));
                $info[$GLOBALS['Did']] = URI($GLOBALS['Did'], $user_id, $db);
                $permission2add[$GLOBALS['Did']] = $info[$GLOBALS['Did']]['add_data'];
                $core_score[$GLOBALS['Did']] = 8;
            }
            #echo '<pre>';print_r($input_ids);exit;
            #echo '<pre>';print_r($inserteable);
            #echo '<pre>';print_r($s3ql);exit;
            ############################
            #this next segment finds all the s3ids in the query, and checks permission of user/session on it (user/session beause user ccna be using a group)
            #echo '<pre>';print_r($s3ql);
            if (ereg('^(U|G|P|C|R|I|S|F)$', strtoupper(substr($element, 0, 1)))) {
                foreach ($inserteable as $s3element => $id) {
                    if ($s3ql['where'][$id] != '') {
                        $element_name = $s3element;
                        $id_name = $id;
                        $uid_info = uid(strtoupper(substr($element, 0, 1)) . $s3ql['where'][$id_name]);
                        $element_info = retrieveUIDInfo($s3element, $id, $scoreTable, $s3ql, $letter, $input_ids, $user_id, $db);
                        #echo '<pre>';print_r($element_info);
                        $info[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = $element_info;
                        $permission2add[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = $element_info['add_data'];
                        $core_score[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = $scoreTable[$element_name];
                        #when element id is present (customized elemnt-id, and is the only ID, and id already exists, user cannot recreat it. To update it, he must go through update. That is the only ID that can "Not" exist
                        if ($id == $GLOBALS['s3ids'][$element] && !is_array($element_info)) {
                            #if a particular id was not found and user is trying to customize a new element_id, then user will have permission to add to it.
                            $permission2add[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = '1';
                        } else {
                            if (!is_array($element_info) && $uid_info['Did'] == $GLOBALS['Did']) {
                                return formatReturn($GLOBALS['error_codes']['no_results'], 'Resource ' . strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name] . ' was not found', $format, '');
                                #if($s3ql['format']=='')
                                #return ('<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '',$GLOBALS['messages']['something_does_not_exist']).'</TD><TD>>Resource '.strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name].' was not found</TD></TR></TABLE>');
                                #else
                                #return ($GLOBALS['messages']['something_does_not_exist'].'<message>Resource '.strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name].' was not found</message>');
                            }
                        }
                    }
                }
                #echo 'ola<pre>';print_r($info);exit;
                #echo '<pre>';print_r($permission2add);
                #echo '<pre>';print_r($core_score);
                #exit;
                $result = array_combine($core_score, $permission2add);
                #score as index and permissions as values
                #a group and a user can be inserted in any one resource... as long as user does have permission on the resource
                if (ereg('^(U|G)$', $letter)) {
                    if ($result[min(array_keys($result))] || $user_info['account_type'] == 'a' && max(array_keys($result)) == 8) {
                        $result[max(array_keys($result))] = '1';
                    }
                }
                $has_permission2add = $result[max(array_keys($result))];
                #this means the highest scored element does NOT have permission to add
                #echo '<pre>';print_r($result);exit;
                #how many IDS?Min ID is 1; if two, then it can be inserting a statement or adding remote resource on local resource
                #print $info
                ####If any s3ids were found, Variable $info was created, and variable $permission2add was created from the first.
                #now,interpret what was found.
                #Permissions need to be checek if any ID is supplied that already exists.
                #if (ereg('(group|user|project|collection|rule|item|statement|file)', $element)) {
                if (ereg('(G|U|P|C|R|I|S|F)', strtoupper(substr($element, 0, 1)))) {
                    if (count($info) == '1' || count($info) == '2' && $info[$GLOBALS['Did']] != '' || count($info) == '2' && ereg('^(statement|file)$', $element)) {
                        #is this ID from the element we are trying to insert?
                        #does it exist?
                        if ($s3ql['where'][$GLOBALS['COREids'][$element]] != '' && isLocal($uid, $db) && !$info[$uid]['is_remote']) {
                            #cannot recreate id. Do nothing.
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], $uid . ' already exists. Could not recreate it.', $format, '');
                        } elseif (count($info) == '1' && $element_id != '') {
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide the uid where this ' . $element . ' should be inserted.', $format, '');
                        } else {
                            #take inputs, validate them, check permission on ONE id, create resource. Do the switch cases here.
                            if ($has_permission2add) {
                                #this means the highest value on permission2asd is 1.
                                if ($info[$uid]['to_create'] == '1' || $element_id == '') {
                                    $create_info = $s3ql['where'];
                                    #echo '<pre>';print_r($create_info);	exit;
                                    #echo 'ola';exit;
                                    $inputs = gatherInputs(array('element' => $element, 'info' => $info, 'to_create' => $create_info, 'user_id' => $user_id, 'db' => $db));
                                    $info = $inputs;
                                    #echo 'inputs<pre>';print_r($inputs);exit;
                                    if (!is_array($inputs)) {
                                        return formatReturn('3', $inputs, $format, '');
                                    }
                                    $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key', 'user_id', 'format'));
                                    #echo 'validity<pre>';print_r($validity);exit;
                                    if ($validity[0]) {
                                        $key = $s3ql['key'];
                                        $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
                                        #echo '<pre>';print_r($inserted);exit;
                                        return formatReturn('0', $inserted[4], $format, array($element . '_id' => $inserted[$element . '_id']));
                                    } else {
                                        #echo '<pre>';print_r($validity);
                                        return formatReturn($validity['error_code'], $validity['message'], $format, '');
                                    }
                                } elseif ($info[$uid]['is_remote'] == '1') {
                                    #insert the permission on local
                                    #remote users an dgroups are inserted ON TABLE
                                    if (ereg('user|group|project', $element)) {
                                        #echo '<pre>';print_r($info[$uid]);exit;
                                        $create_info = $info[$uid];
                                        $create_info['account_email'] = $info[$uid]['account_email'] == '' ? '*****@*****.**' : $info[$uid]['account_email'];
                                        $create_info['account_lid'] = $info[$uid]['account_lid'] != '' ? $info[$uid]['account_lid'] : $info[$uid]['account_id'];
                                        $inputs = gatherInputs(array('element' => $element, 'info' => $info, 'to_create' => $create_info, 'user_id' => $user_id, 'db' => $db));
                                        #echo '<pre>';print_r($inputs);exit;
                                        if (!is_array($inputs)) {
                                            return $inputs;
                                        }
                                        $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                                        #echo '<pre>';print_r($validity);exit;
                                        if ($validity[0]) {
                                            $key = $s3ql['key'];
                                            $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
                                            return formatReturn('0', $element . ' inserted.', array($element . '_id' => $inserted[$element . '_id'], $s3ql['format']));
                                        } else {
                                            return $validity[1];
                                        }
                                    }
                                    $permission_info = array('uid' => $uid, 'shared_with' => 'U' . $user_id, 'permission_level' => $info[$uid]['acl']);
                                    $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                    if (!$permission_added) {
                                        $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                    }
                                    if ($permission_added) {
                                        return formatReturn($GLOBALS['error_codes']['success'], $uid . " shared_with in " . $permission_info['shared_with'], $format, '');
                                        #return $GLOBALS['messages']['success']."<message> ".$uid." shared_with in ".$permission_info['shared_with']."</message>";
                                    } else {
                                        return formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Could not share " . $uid . " with " . $permission_info['shared_with'], $format, '');
                                        #return $GLOBALS['messages']['something_went_wrong']."<message>Could not share ".$uid." with ".$permission_info['shared_with']."</message>";
                                    }
                                }
                            } else {
                                $no_permission_id = array_search('0', $permission2add);
                                return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to insert in ' . $no_permission_id, $format, '');
                                exit;
                                #return ($GLOBALS['messages']['no_permission_message'].' Reason: <message>User does not have permission to insert in '.$no_permission_id.'</message>');
                            }
                        }
                    } elseif (count($info) >= 2) {
                        #echo '<pre>';print_r($info);exit;
                        #2 or + ids in info.
                        #these IDS can be entity_id OR membership
                        if ($element_id != '' && !$info[$uid]['to_create']) {
                            #grant permissions
                            $shared_with = array_diff(array_keys($permission2add), array($uid));
                            #take uid from the keys of permission2add, that point to the uid we are sharing with
                            $shared_with = $shared_with[0];
                            $add_resource_on_resource = substr(has_permission(compact('uid', 'shared_with'), $db), 2, 1);
                            if (!$has_permission2add) {
                                #statement has rule_id and instance_id, user must have permission on both.
                                return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to insert in resource ' . key($permission2add), $format, '');
                            }
                            #return ($GLOBALS['messages']['no_permission_message'].'<message>User does not have permission to insert in resource '.key($permission2add).'</message>');
                            if ($result[max(array_keys($result))] == '0' && $result[min(array_keys($result))] == '1' && $add_resource_on_resource != '1' && $element != 'user') {
                                return formatReturn($GLOBALS['error_codes']['something_missing'], 'To share ' . $uid . ' owner of ' . $shared_with . ' must insert first ' . $uid . ' in ' . $shared_with . '.', $s3ql['format'], '');
                            } else {
                                #if is remote and user cna insert in resource, must be inserted first
                                if ($info[$uid]['to_create']) {
                                    $create_info = $s3ql['where'];
                                    #echo '<pre>';print_r($create_info);	exit;
                                    $inputs = gatherInputs(array('element' => $element, 'info' => $info, 'to_create' => $create_info, 'user_id' => $user_id));
                                    if (!is_array($inputs)) {
                                        return $inputs;
                                    }
                                    $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                                    if ($validity[0]) {
                                        $key = $s3ql['key'];
                                        $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
                                        return formatReturn('0', $element . ' inserted.', array($element . '_id' => $inserted[$element . '_id'], $s3ql['format']));
                                    } else {
                                        return $validity[1];
                                    }
                                }
                                if ($info[$uid]['is_remote']) {
                                    #the other iD, non element id, should be the upper ID, where user shoulsd already have intert permission
                                    $diff = array_diff(array_keys($permission2add), array($uid));
                                    $shared_with = $diff[0];
                                    $permission_info = array('uid' => $uid, 'shared_with' => $shared_with, 'permission_level' => $info[$uid]['acl']);
                                    $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                    if (!$permission_added) {
                                        $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                    }
                                    if ($permission_added) {
                                        return formatReturn($GLOBALS['error_codes']['success'], $uid . " inserted in " . $shared_with, $s3ql['format'], '');
                                    } else {
                                        return formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Could not share " . $uid . " with " . $permission_info['shared_with'], $format, '');
                                        #return $GLOBALS['messages']['something_went_wrong']."<message>Could not share ".$uid." with ".$permission_info['shared_with']."</message>";
                                    }
                                }
                                if (!$info[$uid]['to_create'] && $s3ql['where']['permission_level'] == '') {
                                    #does it exist already in upper resource?
                                    $diff = array_diff(array_keys($permission2add), array($uid));
                                    $shared_with = $diff[0];
                                    $sql = str_replace($GLOBALS['regexp'], '=', select(compact('uid', 'shared_with')));
                                    #echo $sql;exit;
                                    $db->query($sql, __LINE__, __FILE__);
                                    if ($db->next_record()) {
                                        return formatReturn($GLOBALS['error_codes']['repeating_action'], $uid . ' already shared with ' . $shared_with . '. You can change its level of permission by indicating permission_level.', $s3ql['format'], '');
                                    }
                                }
                            }
                            #share according to permissions
                            $uid2share = array_search(min($core_score), $core_score);
                            $shared_with = array_search(max($core_score), $core_score);
                            $uid_info = uid($uid2share);
                            if ($result[max(array_keys($result))] == '1' || $add_resource_on_resource && $result[min(array_keys($result))] == '1') {
                                #echo 'ola';exit;
                                $case = '2';
                                $uid_info = uid($uid2share);
                                if ($uid_info['Did'] == $GLOBALS['Did']) {
                                    $uid2share = $uid_info['uid'];
                                }
                                #$uid2share = strtoupper(substr($uid_info['uid'],0,1)).$GLOBALS['Did'].'/'.$uid_info['uid'];
                                $permission_info = array('uid' => $uid2share, 'shared_with' => $shared_with, 'permission_level' => $s3ql['where']['permission_level'] != '' ? $s3ql['where']['permission_level'] : '210');
                                #echo '<pre>';print_r($permission_info);exit;
                                $validity = validate_permission(compact('permission_info', 'user_id', 'db', 'info'));
                                #grant project_id permission on rule_id
                                #echo $validity;exit;
                                if ($validity == '0') {
                                    $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                } elseif ($validity == '2') {
                                    $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                } elseif ($validity == '6' && ereg('^G', $shared_with) && ereg('^U', $uid)) {
                                    $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                    #grant rule_id permission on project_id
                                    $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                } elseif ($validity == '6') {
                                    return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User must have permission ' . $permission_info['permission_level'] . ' or greater to grant permission ' . $permission_info['permission_level'] . ' on ' . $permission_info['shared_with'], $format, '');
                                }
                                #return ($GLOBALS['messages']['no_permission_message'].'<message>User must have permission '.$permission_info['permission_level'].' or greater to grant permission '.$permission_info['permission_level'].' on '.$permission_info['shared_with'].'.</message>');
                            } elseif ($result[max(array_keys($result))] == '1' && $result[min(array_keys($result))] == '0') {
                                $case = '1';
                                if ($uid_info['Did'] == $GLOBALS['Did']) {
                                    $uid2share = strtoupper(substr($uid_info['uid'], 0, 1)) . $GLOBALS['Did'] . '/' . $uid_info['uid'];
                                }
                                $permission_info = array('shared_with' => $shared_with, 'uid' => $uid2share, 'permission_level' => '001');
                                $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                if (!$permission_added) {
                                    $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
                                }
                                #This step will leave rule insert pending until owner of the rule comes by and inserts it in project
                            }
                            if ($permission_added) {
                                #Missing: Create an entry in access_rules with "Pending" statuss
                                if ($case == '1') {
                                    return formatReturn($GLOBALS['error_codes']['success'], "Permission on " . $permission_info['uid'] . " requested and pending.", $format, '');
                                } else {
                                    return formatReturn($GLOBALS['error_codes']['success'], $permission_info['uid'] . " inserted in " . $permission_info['shared_with'], $s3ql['format'], '');
                                }
                            } else {
                                return formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Could not share " . $permission_info['uid'] . " with " . $permission_info['shared_with'], $s3ql['format'], '');
                            }
                        } elseif ($info[$uid]['to_create'] || $info[$uid]['is_remote']) {
                            #insert IF is remote or was asserted to be inserted
                            if (is_array($info[$uid]) && $info[$uid]['is_remote']) {
                                $create_info = $info[$uid];
                            } else {
                                $create_info = $s3ql['where'];
                            }
                            $inputs = gatherInputs(array('element' => $element, 'to_create' => $create_info, 'user_id' => $user_id, 'info' => $info));
                            #echo '<pre>';print_r($inputs);exit;
                            if (!is_array($inputs)) {
                                return $inputs;
                            }
                            $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                            if ($validity[0]) {
                                $key = $s3ql['key'];
                                $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
                                return formatReturn('0', $element . ' inserted.', array($element . '_id' => $inserted[$element . '_id']), $s3ql['format']);
                            } else {
                                return $validity[1];
                            }
                        }
                    }
                }
            }
            #permissions to add are stored in $permission2add, but when we are inserting an existing idA on an existing idB, we do not need permission to add_data on A, only on B. So the users does not need insert permission on idA, if idA is further down the graph then idB.
            #if there is only 1 id, and there is no insert permission, it can break
            #start some special cases
            switch ($element) {
                case 'key':
                    ##INSERT KEY
                    #when no key is given, generate a random one
                    if ($s3ql['where']['key_id'] == '') {
                        $s3ql['where']['key_id'] = random_string('15');
                    }
                    if ($s3ql['where']['expires'] == '') {
                        $s3ql['where']['expires'] = date('Y-m-d H:i:s', time() + 1 * 24 * 60 * 60);
                    }
                    #expires in 24h
                    #user can chose to insert a key for a specific ID, be it group, project, rule or statement (anywhere where permissions can be defined)
                    $I['inputs'] = array_merge($s3ql['where'], array('account_id' => $user_id));
                    $validate = validate_access_key_inputs(array('inputs' => $I['inputs'], 'db' => $db, 'user_id' => $user_id));
                    switch ($validate) {
                        case 0:
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Expiration date is missing', $s3ql['format'], '');
                            break;
                        case 1:
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Key is too short. Please input a key longer than 10 char', $s3ql['format'], '');
                            break;
                        case 2:
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Invalid date format', $s3ql['format'], '');
                            break;
                        case 3:
                            return formatReturn($GLOBALS['error_codes']['repeating_action'], 'Key ' . $s3ql['where']['key_id'] . ' is not valid. Please chose another key', $s3ql['format'], '');
                            break;
                        case 4:
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Expiration date must be bigger than present date.', $s3ql['format'], '');
                            break;
                        case 6:
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], 'UID ' . $s3ql['where']['UID'] . ' does not exist', $s3ql['format'], '');
                            break;
                        case 7:
                            return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'UID ' . $s3ql['where']['UID'] . ' does not belong to user.', $s3ql['format'], '');
                            break;
                        case 8:
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Please use only numbers and letter in your keys.', $s3ql['format'], '');
                            break;
                        case 5:
                            add_entry('access_keys', $I['inputs'], $db);
                            $output = formatReturn($GLOBALS['error_codes']['success'], 'Key created.', $s3ql['format'], array('key_id' => $s3ql['where']['key_id']));
                            return $output;
                    }
                    break;
                case 'file':
                    $resource_id = $s3ql['where']['item_id'] != '' ? $s3ql['where']['item_id'] : $s3ql['where']['instance_id'];
                    $rule_id = $s3ql['where']['rule_id'];
                    $filekey = $s3ql['where']['filekey'];
                    $notes = $s3ql['where']['notes'];
                    if ($resource_id == '' || $rule_id == '' || $filekey == '') {
                        return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide all the necessary inputs: rule_id, item_id, filekey', $format, '');
                        #return ($GLOBALS['messages']['something_missing'].'<message>Please provide all the necessary inputs: rule_id, item_id, filekey</message>');
                    }
                    #Check permission on inserting statements for specific projects
                    #Check permission on inserting statements for specific projects
                    $rule_info = $info['R' . $rule_id];
                    $instance_info = $info['I' . $resource_id];
                    #$instance_info = URIinfo('I'.$resource_id, $user_id, $key, $db);
                    if ($rule_info['object'] == 'UID') {
                        return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Please use this query only for rules that do NOT enumerate classes. For inserting on other rules, use the query for insert instance', $format, '');
                        #return $wrong_input."<message>Please use this query only for rules that do NOT enumerate classes. For inserting on other rules, use the query for insert instance</message>";
                    } elseif (!is_array($instance_info)) {
                        return formatReturn($GLOBALS['error_codes']['no_results'], 'Item ' . $resource_id . ' was not found', $format, '');
                        #return ($something_does_not_exist.'<message>Instance '.$resource_id.' was not found</message>');
                    } elseif ($instance_info['resource_class_id'] != $rule_info['subject_id']) {
                        return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Subject of rule does match Class of instance', $format, '');
                        #return $wrong_input."<message>Subject of rule does match Class of instance</message>";
                    } elseif ($filekey == '') {
                        return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please indicate a filekey for this file', $format, '');
                    }
                    #return $wrong_input."<message>Please indicate a filekey for this file</message>";
                    #Find out if the file already exists in the tmp directory
                    $fileFinalName = get_entry('file_transfer', 'filename', 'filekey', $filekey, $db);
                    $file_id = get_entry('file_transfer', 'file_id', 'filekey', $filekey, $db);
                    ereg('([A-Za-z0-9]+)\\.*([A-Za-z0-9]*)$', $fileFinalName, $tokens);
                    $name = $tokens[1];
                    $extension = $tokens[2];
                    #list($name, $extension) = explode('.', $fileFinalName);
                    $maindir = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'] . '/tmps3db';
                    $old_file = $maindir . '/' . $file_id . '.' . $extension;
                    if (!is_file($old_file)) {
                        return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'File not found, please upload file first.', $format, '');
                    } else {
                        #project_id will be that of the rule, except if user does not have permission on it.
                        $project_info = URI('P' . $rule_info['project_id'], $user_id, $db);
                        $project_id = $s3ql['where']['project_id'] != '' ? $s3ql['where']['project_id'] : ($project_info['add_data'] ? $class_info['project_id'] : '');
                        if ($project_id == '') {
                            $project_id = $rule_info['project_id'];
                            #$user_projects = findUserProjects($user_id, $db);
                            //							$user_projects = array_map('grab_project_id', $user_projects);
                            //
                            //
                            //							#find the projects that can access the rule
                            //							$allowed_projects = array_filter(explode('_', $rule_info['permission']));
                            //
                            //							$both = array_intersect($allowed_projects, $user_projects);
                            //
                            //							if (is_array($both)) {
                            //								foreach ($both as $key=>$allowed_project_id) {
                            //									if(substr(has_permission(array('uid'=>'R'.$rule_id, 'shared_with'=>'P'.$allowed_project_id), $db), 2,1))
                            //										$project_id = $allowed_project_id;
                            //								}
                            //							}
                        }
                        if ($project_id == '') {
                            return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Failed to find a project_in for this intance', '', $s3ql['format']);
                        }
                        $value = project_folder_name($project_id, $db);
                        $created_by = $user_id;
                        $filesize = filesize($old_file);
                        $filename = $fileFinalName;
                        ##Create the row in the statements table
                        $create_info = $s3ql['where'];
                        #echo '<pre>';print_r($s3ql);
                        $inputs = gatherInputs(array('element' => 'file', 'info' => $info, 'to_create' => $create_info, 'user_id' => $user_id, 'db' => $db));
                        $info = $inputs;
                        if (!is_array($inputs)) {
                            return formatReturn('3', $inputs, $s3ql['format'], '');
                        }
                        $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key', 'user_id'));
                        #echo '<pre>';print_r($validity);exit;
                        if ($validity[0]) {
                            $key = $s3ql['key'];
                            $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
                            ##Move the file
                            $S = compact('user_id', 'project_id', 'resource_id', 'rule_id', 'value', 'notes', 'created_by', 'filename', 'filesize', 'extension', 'db');
                            $S['statement_id'] = $inserted['statement_id'];
                            $S['uploadedfile'] = $old_file;
                            $fileRelocated = movefile2folder($S);
                            if (!$fileRelocated) {
                                $sql = "delete from s3db_statement where statement_id = '" . $S['statement_id'] . "'";
                                $db->query($sql, __FILE__, __LINE__);
                                #echo $sql;
                                return formatReturn('2', 'File could not be imported. Please try again.', '', $s3ql['format']);
                                #unlink($old_file);
                            } else {
                                return formatReturn($GLOBALS['error_codes']['success'], 'File inserted.', $s3ql['format'], array('file_id' => $inserted['1']));
                                #if($s3ql['format']=='')
                                #	return ('<TABLE><TR><TD>error_code</TD><TD>message</TD><TD>'.$element.'_id</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '', $inserted[3]).'</TD><TD>'.$inserted[4].'</TD><TD>'.$inserted[$element.'_id'].'</TD></TR></TABLE>');
                                #else
                                #	return ($inserted[1]);
                            }
                        } else {
                            #echo '<pre>';print_r($validity);
                            return formatReturn(ereg_replace('[^(0-9)]', '', $inserted[3]), $validity[1], $format, '');
                            #if($s3ql['format']=='')
                            #	return ('<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '', $inserted[3]).'</TD><TD>'.$validity[1].'</TD></TR></TABLE>');
                            #else
                            #return ($validity[1]);
                        }
                        ##Move the file
                        if ($statement_inserted) {
                            $S['statement_id'] = find_latest_UID('statement', $db);
                            $S['uploadedfile'] = $old_file;
                            $fileRelocated = movefile2folder($S);
                            if ($fileRelocated) {
                                return formatReturn($GLOBALS['error_codes']['success'], "File inserted", array('file_id' => $S['file_id']), $s3ql['format']);
                            } else {
                                return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Failed to move file', $format, '');
                            }
                            #else return $something_went_wrong."<message>Failed to move file</message>";
                        }
                    }
                    #This ends "is not a file"
                    #This ends insert file
                    break;
            }
            #finish element switch
            break;
            #Finish insert
        #Finish insert
        case 'edit':
            if ($s3ql['edit'] == 'class') {
                $s3ql['edit'] = 'collection';
            }
            if ($s3ql['edit'] == 'instance') {
                $s3ql['edit'] = 'item';
            }
            if ($s3ql['set']['notes'] != '') {
                $s3ql['set']['notes'] = utf8_encode($s3ql['set']['notes']);
            }
            if ($s3ql['set']['value'] != '') {
                $s3ql['set']['value'] = utf8_encode($s3ql['set']['value']);
            }
            #$element = $s3ql[$action];
            $element = $s3ql['edit'];
            #echo 'ola<pre>';print_r($s3ql);exit;
            $set = array('project' => array('project_name', 'project_description', 'project_owner', 'permission_level'), 'collection' => array('project_id', 'entity', 'notes'), 'rule' => array('project_id', 'subject', 'verb', 'object', 'subject_id', 'verb_id', 'object_id', 'notes', 'validation'), 'item' => array('project_id', 'collection_id', 'notes'), 'statement' => array('project_id', 'item_id', 'rule_id', 'value', 'notes'), 'user' => array('account_lid', 'account_pwd', 'account_uname', 'account_email', 'account_phone', 'addr1', 'addr2', 'account_type', 'city', 'postal_code', 'state', 'country', 'account_status'), 'group' => array('account_lid'));
            $E = compact('db', 'user_id', 's3ql');
            #first of all, is this a valid target?
            if (!in_array($s3ql['edit'], array_keys($set))) {
                return formatReturn($GLOBALS['error_codes']['wrong_input'], $s3ql['edit'] . " is not a valid S3DB element. Valid elements: project, collection, rule, item, statement", $s3ql['format'], '');
            }
            #is there an ID to locate the appropriate resource?
            if ($s3ql['where'][$element . '_id'] == '') {
                return formatReturn($GLOBALS['error_codes']['something_missing'], 'ID of ' . $element . ' to edit is missing', $s3ql['format'], '');
            }
            if ($s3ql['set'] == '') {
                #is it in where?
                $s3ql['set'] = array_diff_key($s3ql['where'], array($element . '_id' => ''));
                if ($s3ql['set'] == '') {
                    return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please specify what you want to update.' . $syntax_message, $s3ql['format'], '');
                }
            }
            #interpret input
            $s3map = $GLOBALS['s3map'];
            foreach ($s3map[$GLOBALS['plurals'][$element]] as $alter_name => $name) {
                if ($s3ql['set'][$alter_name] != '') {
                    $s3ql['set'][$name] = $s3ql['set'][$alter_name];
                }
            }
            $s3ql['set'] = array_diff_key($s3ql['set'], $s3map[$GLOBALS['plurals'][$element]]);
            $s3ql['set'] = array_filter($s3ql['set']);
            #detect is something that is something in set that cannot be updated
            $test_set = array_intersect($set[$element], array_keys($s3ql['set']));
            $extra_fields = array_diff(array_keys($s3ql['set']), $test_set);
            if (count($s3ql['set']) > count($test_set)) {
                #this means that there are fields that don't exist
                foreach ($extra_fields as $field_name) {
                    $output .= '<message>Warning: ' . $field_name . ' is not a valid property of ' . $element . '. ' . $field_name . ' will not be updated. Valid properties: ' . rtrim(array_reduce($set[$element], 'comma_split'), ', ') . '</message>';
                }
            }
            #retrieve information about resource
            $element_id = $s3ql['where'][$element . '_id'];
            $uid = strtoupper(substr($element, 0, 1)) . $element_id;
            $e_info = URIinfo($uid, $user_id, $key, $db);
            #echo '<pre>';print_r($e_info);
            if (!is_array($e_info)) {
                return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], '' . $element . ' ' . $element_id . ' was not found.');
            } elseif (!$e_info['change']) {
                return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to change this ' . $element, $s3ql['format'], '');
            }
            foreach ($e_info as $field => $data) {
                if ($s3ql['set'][$field] != '' || $field == 'notes') {
                    if (in_array($field, $set[$element])) {
                        $oldvalues[$field] = $e_info[$field];
                        $e_info[$field] = $s3ql['set'][$field];
                        $inputs[$field] = $s3ql['set'][$field];
                    }
                }
            }
            #echo '<pre>';print_r($inputs);
            switch ($element) {
                case 'user':
                    ##EDIT USER
                    $user_to_change_info = get_info('user', $element_id, $db);
                    #this is necessary because password will not come in the $e_info var.
                    #permission was checked before the switch
                    #map values
                    $s3map = array('login' => 'account_lid', 'password' => 'account_pwd', 'username' => 'account_uname', 'email' => 'account_email', 'phone' => 'account_phone', 'address' => 'addr1', 'address2' => 'addr2', 'city' => 'city', 'state' => 'state', 'postal_code' => 'postal_code', 'country' => 'country', 'account_type' => 'account_type');
                    #encript the password
                    #echo '<pre>';print_r($s3ql);exit;
                    if ($s3ql['set']['password'] != '' || $s3ql['set']['account_pwd']) {
                        $s3ql['set']['password'] = $s3ql['set']['account_pwd'] != '' ? md5($s3ql['set']['account_pwd']) : md5($s3ql['set']['password']);
                    } else {
                        $s3ql['set']['password'] = $user_to_change_info['account_pwd'];
                    }
                    #echo '<pre>';print_r($s3ql);
                    #login, password and email cannot be deleted so if they come empty, fill them out with the old values
                    $non_erasable = array('login', 'email', 'username', 'password');
                    foreach ($non_erasable as $fieldname) {
                        if (in_array($fieldname, array_keys($s3ql['set']))) {
                            if ($s3ql['set'][$fieldname] == '') {
                                return formatReturn($GLOBALS['error_codes']['wrong_input'], 'login, email, username and password cannot be deleted', $s3ql['format'], '');
                            }
                        } elseif (!in_array($fieldname, array_keys($s3ql['set']))) {
                            #then start filling out input with the old values
                            $inputs[$s3map[$fieldname]] = $e_info[$s3map[$fieldname]];
                        }
                    }
                    #now map the valid values
                    foreach (array_keys($s3ql['set']) as $set) {
                        if (in_array($set, array_keys($s3map))) {
                            if ($s3ql['set'][$set] != '') {
                                $inputs[$s3map[$set]] = $s3ql['set'][$set];
                            }
                        }
                    }
                    #echo '<pre>';print_r($e_info);
                    $inputs['account_type'] = $s3ql['set']['account_type'] != '' ? $s3ql['set']['account_type'] : $user_to_change_info['account_type'];
                    $inputs['account_status'] = $s3ql['set']['account_status'] != '' ? $s3ql['set']['account_status'] : $user_to_change_info['account_status'];
                    $inputs['account_group'] = $inputs['account_type'];
                    #replace in $e_info the values with the inputs. First clean the existing one, then merge with the new one
                    $user_info = array_diff_key($e_info, $inputs);
                    $user_info = array_merge($user_info, $inputs);
                    $validity = validate_user_inputs(array('inputs' => $inputs, 'imp_user_id' => $e_info['account_id'], 'db' => $db, 'action' => 'update'));
                    $info = $e_info;
                    #echo '<pre>';print_r($inputs);
                    #$validity = validateInputs(compact('element','info', 'inputs', 'oldvalues', 'user_id', 'db'));
                    #echo '<pre>';print_r($validity);
                    switch ($validity) {
                        case 0:
                            #echo '<pre>';print_r($user_info);	exit;
                            if (!update_user(compact('user_info', 'db', 'user_id'))) {
                                #$output .= $something_went_wrong;
                                return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'User could not be updated. Undetermined reasons.', $s3ql['format'], '');
                            } else {
                                #$output .= $GLOBALS['messages']['success'];
                                #$output .= '<message> User updated</message>';
                                return formatReturn($GLOBALS['error_codes']['success'], 'User updated', $s3ql['format'], '');
                            }
                            break;
                        case 1:
                            #$output .= $GLOBALS['messages']['something_missing'];
                            #$output .= '<message> Login is missing.'.$syntax_message.'</message>';
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Login is missing.' . $syntax_message, $s3ql['format'], '');
                            break;
                        case 2:
                            #$output .= $GLOBALS['messages']['something_missing'];
                            #$output .= '<message> Account_type is missing.'.$syntax_message.'</message>';
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Account_type is missing.' . $syntax_message, $s3ql['format'], '');
                            break;
                        case 3:
                            #$output .= $GLOBALS['messages']['something_missing'];
                            #$output .= '<message> Username is missing.'.$syntax_message.'</message>';
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Username is missing.' . $syntax_message, $s3ql['format'], '');
                            break;
                        case 4:
                            #$output .= $GLOBALS['messages']['something_missing'];
                            #$output .= '<message> Account status is missing.'.$syntax_message.'</message>';
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Account status is missing.' . $syntax_message, $s3ql['format'], '');
                            break;
                        case 5:
                            $output .= $GLOBALS['messages']['something_missing'];
                            $output .= '<message> Password is missing.' . $syntax_message . '</message>';
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'Password is missing.' . $syntax_message, $s3ql['format'], '');
                            break;
                        case 6:
                            #$output .= $GLOBALS['messages']['something_missing'];
                            return formatReturn($GLOBALS['error_codes']['something_missing'], '', $s3ql['format'], '');
                            break;
                        case 7:
                            #$output .= $GLOBALS['messages']['something_missing'];
                            return formatReturn($GLOBALS['error_codes']['something_missing'], '', $s3ql['format'], '');
                            break;
                        case 8:
                            #$output .=$GLOBALS['messages']['repeating_action'].'<message> User '.$inputs['account_lid'].' already exists</message>';
                            return formatReturn($GLOBALS['error_codes']['something_missing'], 'User ' . $inputs['account_lid'] . ' already exist', $s3ql['format'], '');
                            break;
                    }
                    break;
                case 'group':
                    ##EDIT GROUP
                    $info = $e_info;
                    $group_id = $info['group_id'];
                    $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                    if ($validity[0]) {
                        if (update_group(compact('inputs', 'group_id', 'user_id', 'db'))) {
                            return formatReturn($GLOBALS['error_codes']['success'], 'G' . $group_id . ' successfully updated', $s3ql['format'], '');
                            #return ($GLOBALS['messages']['success'].'<message>G'.$group_id.' successfully updated</message>');
                        } else {
                            return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'G' . $group_id . ' could not be updated. Reason undetermined.', $s3ql['format'], '');
                            #return ($GLOBALS['messages']['something_went_wrong']);
                        }
                        break;
                    } else {
                        return $validity[1];
                    }
                    break;
                case 'project':
                    ##EDIT PROJECT
                    $project_info = $e_info;
                    $U = compact('project_info', 'db', 'user_id');
                    #$validity = validate_project_inputs($U);
                    $info = $e_info;
                    $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                    if ($validity[0]) {
                        if (update_project($U)) {
                            return formatReturn($GLOBALS['error_codes']['success'], $element . " P" . $element_id . " updated.", $s3ql['format'], '');
                        } else {
                            return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Failed to update project!', $s3ql['format'], '');
                        }
                    } else {
                        #break validity in error and message
                        ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', $validity[1], $valOut);
                        return formatReturn($valOut[1], $valOut[3], $s3ql['format'], '');
                    }
                    break;
                case 'collection':
                    ##EDIT CLASS
                    $resource_info = $e_info;
                    $editresource = compact('db', 'user_id', 'resource_info', 'action', 'inputs', 'oldvalues');
                    $info = $e_info;
                    $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                    #echo '<pre>';print_r($validity);exit;
                    #echo $validity = validate_resource_inputs($editresource);exit;
                    if ($validity[0]) {
                        if (update_resource($editresource)) {
                            #$validity[1].'<br><message>'.$element.' updated</message>';
                            $output .= formatReturn('0', $element . " C" . $element_id . ' updated', $format, '');
                            return $output;
                            #return ($output);
                        }
                    } else {
                        ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', $validity[1], $valOut);
                        return formatReturn($valOut[1], $valOut[3], $s3ql['format'], '');
                        #return ($validity[1]);
                    }
                    break;
                case 'item':
                    ##EDIT INSTANCE
                    #echo '<pre>';print_r($oldvalues);exit;
                    #Does this resource exist?
                    $instance_id = $element_id;
                    $info = $e_info;
                    $notes = $s3ql['set']['notes'];
                    $R = compact('info', 'inputs', 'oldvalues', 'db', 'user_id');
                    $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
                    if ($validity[0]) {
                        if (update_resource_instance($R)) {
                            return formatReturn('0', $element . " I" . $element_id . " updated", $s3ql['format'], '');
                            #$action = 'edit';
                            #$statement_info = $info;
                            #return ($output);
                        }
                    } else {
                        ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', $validity[1], $valOut);
                        return formatReturn($valOut[1], $valOut[3], $s3ql['format'], '');
                        #return ($validity[1]);
                    }
                    break;
                case 'rule':
                    $rule_id = $element_id;
                    $info = $e_info;
                    if ($info['object'] == 'UID') {
                        if ($s3ql['where']['subject'] != '') {
                            #redirect to change class?
                            $res3ql = array_diff_key($s3ql, array('edit' => '', 'update' => ''));
                            $res3ql['where'] = array_diff_key($res3ql['where'], array('rule_id' => ''));
                            $res3ql = array_merge($res3ql, compact('db', 'user_id'));
                            $res3ql['edit'] = 'class';
                            $res3ql['where']['class_id'] = $info['subject_id'];
                            $done = S3QLaction($res3ql);
                            return $done;
                        } else {
                            return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Rule ' . $element_id . ' cannot be edited. To change the subject of the relation please use edit class', $s3ql['format']);
                        }
                    } else {
                        #permission was verified before switch
                        if ($s3ql['set']['subject_id'] != '') {
                            #for log, need to keep track of old literal as well.
                            $oldvalues['subject'] = $info['subject'];
                            $class_info = s3info('class', $s3ql['set']['subject_id'], $db);
                            if (!is_array($class_info)) {
                                return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'Class ' . $s3ql['set']['subject_id'] . ' does not exist', $format, '');
                                #return ($something_does_not_exist.'<message>Class '.$s3ql['set']['subject_id'].' does not exist</message>');
                            }
                            $info['subject_id'] = $s3ql['set']['subject_id'];
                            $info['subject'] = $class_info['entity'];
                        } else {
                            if ($s3ql['set']['subject'] != '') {
                                $oldvalues['subject_id'] = $info['subject_id'];
                                #for log, need to keep track of old literal as well.
                                $info['subject_id'] = fastClassID(array('entity' => $s3ql['set']['subject'], 'project_id' => $project_id, 'db' => $db));
                            }
                        }
                        if ($s3ql['set']['verb_id'] != '') {
                            $oldvalues['verb'] = $info['verb'];
                            #for log, need to keep track of old literal as well.
                            $instance_info = URI('I' . $s3ql['set']['verb_id'], $user_id, $db);
                            if (!is_array($instance_info)) {
                                return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'Instance ' . $s3ql['set']['verb_id'] . ' does not exist', $s3ql['format'], '');
                            } else {
                                $info['verb'] = $instance_info['notes'];
                            }
                        } else {
                            #turn a literal verb into an instance of a class
                            #class exists in project? no? create it;else find it's
                            $VerbClass = projectVerbClass(array('project_id' => $info['project_id'], 'db' => $db, 'user_id' => $user_id));
                            if (!$VerbClass) {
                                $to_create = array('project_id' => $info['project_id'], 'entity' => 's3dbVerb', 'notes' => 'Collection created by S3DB for holding Verbs');
                                $inputs = gatherInputs(array('element' => 'collection', 'to_create' => $to_create, 'db' => $db, 'user_id' => $user_id));
                                $inserted = insert_s3db(array('element' => 'collection', 'inputs' => $inputs, 'user_id' => $user_id, 'db' => $db));
                                #try again;
                                $VerbClass = projectVerbClass(array('project_id' => $info['project_id'], 'db' => $db, 'user_id' => $user_id));
                            }
                            #now create the instanceVerb
                            if ($VerbClass == '') {
                                return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Rule Could not be updated. No collection was found for the verbs', $s3ql['format'], '');
                            }
                            $inputs = array('resource_class_id' => $VerbClass['resource_id'], 'project_id' => $info['project_id'], 'notes' => $s3ql['where']['verb'] != '' ? $s3ql['where']['verb'] : $info['verb'], 'created_by' => $user_id, 'entity' => $VerbClass['entity'], 'status' => 'A');
                            $inserted = insert_s3db(array('element' => 'instance', 'inputs' => $inputs, 'user_id' => $user_id, 'db' => $db));
                            $info['verb_id'] = $inserted['instance_id'];
                            $info['verb'] = verb4instanceID(array('key' => $s3ql['key'], 'instance_id' => $info['verb_id'], 'db' => $db));
                            #echo '<pre>';print_r($info);exit;
                        }
                        if ($s3ql['set']['object_id'] != '') {
                            $oldvalues['object'] = $info['object'];
                            #for log, need to keep track of old literal as well.
                            $class_info = URI('C' . $s3ql['set']['object_id'], $user_id, $db);
                            if (!is_array($class_info)) {
                                return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'Collection ' . $s3ql['set']['object_id'] . ' does not exist', $s3ql['format'], '');
                            }
                            $info['object_id'] = $s3ql['set']['object_id'];
                            $info['object'] = $class_info['entity'];
                        } else {
                            if ($s3ql['set']['object'] != '') {
                                $oldvalues['object_id'] = $info['object_id'];
                                #for log, need to keep track of old literal as well.
                                $info['object_id'] = fastClassID(array('entity' => $s3ql['set']['object'], 'project_id' => $project_id, 'db' => $db));
                            }
                        }
                        $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'user_id', 'action', 'key'));
                        #echo '<pre>';print_r($info);exit;
                        if ($validity[0]) {
                            if (update_rule(compact('info', 'inputs', 'oldvalues', 'db', 'user_id'))) {
                                return formatReturn('0', $element . ' updated', $s3ql['format'], '');
                                #$output .= $validity[1].'<br><message>'.$element.' updated</message>';
                                #return ($output);
                            } else {
                                return formatReturn($validity[1], $validity[2], $format, '');
                            }
                        } else {
                            return formatReturn($validity[1], $validity[2], $format, '');
                        }
                    }
                    break;
                    #This closes edit rules
                case 'statement':
                    $statement_id = $element_id;
                    $value = $s3ql['set']['value'];
                    $notes = $s3ql['set']['notes'];
                    $rule_id = get_entry('statement', 'rule_id', 'statement_id', $statement_id, $db);
                    $object = get_entry('rule', 'object', 'rule_id', $rule_id, $db);
                    $statement_info = $e_info;
                    $project_id = $statement_info['project_id'];
                    $acl = find_final_acl($user_id, $project_id, $db);
                    #When the value is not being updated, use the old value for the update
                    if ($value == '') {
                        $value = $statement_info['value'];
                    }
                    if (!in_array('notes', array_keys($s3ql['set']))) {
                        $notes = $statement_info['notes'];
                    }
                    #Does the user have permission to change this statement?
                    if (!$statement_info['change']) {
                        return formatReturn($GLOBALS['error_codes']['no_permission_message'], "User does not have permission to change this statement", $s3ql['format'], '');
                    } elseif (resourceObject(array('rule_id' => $statement_info['rule_id'], 'project_id' => $project_id, 'db' => $db)) && !resource_found(array('rule_id' => $statement_info['rule_id'], 'user_id' => $user_id, 'project_id' => $project_id, 'value' => $value, 'db' => $db))) {
                        return formatReturn($GLOBALS['error_codes']['wrong_input'], "Value for this statement must be a valid resource_id from class " . $object, $s3ql['format'], '');
                    } elseif ($statement_info['filename'] != '') {
                        return formatReturn($GLOBALS['error_codes']['wrong_input'], "Statements that contain files must be deleted first and the updated version of the file uploaded", $s3ql['format'], '');
                    } elseif (!validate_statement_value($statement_info['rule_id'], $value, $db)) {
                        $rule_info = s3info('rule', $statement_info['rule_id'], $db);
                        return formatReturn($GLOBALS['error_codes']['wrong_input'], 'The rule of this statement requires validation. Please input value in the format: ' . $rule_info['validation'], $s3ql['format'], '');
                    } else {
                        $modified_by = $user_id;
                        #$oldvalues = array_filter($oldvalues);
                        #$inputs = array_filter($inputs);
                        #echo '<pre>';print_r($oldvalues);exit;
                        $S = compact('statement_id', 'statement_info', 'oldvalues', 'inputs', 'value', 'notes', 'modified_by', 'db', 'user_id');
                        $updated = update_statement($S);
                        if ($updated) {
                            return formatReturn($GLOBALS['error_codes']['success'], $element . " updated", $s3ql['format'], '');
                        } else {
                            return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Statement update failed.', $s3ql['format'], '');
                        }
                    }
                    break;
            }
            #close switch element
            break;
            #close switch action
        #close switch action
        case 'delete':
            #echo '<pre>';print_r($s3ql);
            if ($s3ql['delete'] == 'class') {
                $s3ql['delete'] = 'collection';
            }
            if ($s3ql['delete'] == 'instance') {
                $s3ql['delete'] = 'item';
            }
            #echo '<pre>';print_r($s3ql);
            #map queries
            if ($s3ql['where']['resource_id'] != '') {
                if ($s3ql['delete'] == 'instance') {
                    $s3ql['where']['item_id'] = $s3ql['where']['resource_id'];
                } elseif ($s3ql['delete'] == 'class') {
                    $s3ql['where']['collection_id'] = $s3ql['where']['resource_id'];
                }
            }
            $element = $s3ql['delete'];
            $letter = letter($element);
            $possible = array('key', 'project', 'collection', 'rule', 'item', 'statement', 'user', 'group', 'permission');
            $D = compact('db', 'user_id', 's3ql');
            if (!in_array($element, array_keys($possible))) {
                #return $not_a_query;
                return formatReturn($GLOBALS['error_codes']['not_a_query'], $element . ' is not a valid s3db element.', $format, '');
            }
            #is there an ID to locate the appropriate resource?
            $element_id = $s3ql['where'][$element . '_id'];
            if ($element_id == '' && $element != 'permission') {
                return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please specify ' . $element . '_id' . ' to delete', $format, '');
            }
            #return ($something_missing.'<message>Please specify '.$element.'_id'.' to delete</message>');
            $uid_info = uid($element_id);
            if (!ereg('^(U|G|P|C|R|I|S)', $uid_info['uid'])) {
                $uid_info['uid'] = strtoupper(substr($element, 0, 1)) . $uid_info['uid'];
            }
            $uid = $uid_info['uid'];
            #$e_info = URIinfo($uid['Did'].'/'.$uid['uid'],$user_id,$key, $db);
            #how many "deleateable" ids are on the query?
            $deleteable = array('group' => 'group_id', 'user' => 'user_id', 'project' => 'project_id', 'rule' => 'rule_id', 'collection' => 'collection_id', 'item' => 'item_id', 'statement' => 'statement_id');
            #scoreTable will allow us to score the elements according to their position in the inheritance model. To chose the correct permission level
            $scoreTable = array_reverse($deleteable, 0);
            $scoreTable = array_combine(array_keys($scoreTable), range(1, count($deleteable)));
            if (ereg('user|project|group', $element) && count(array_filter(array_diff_key($s3ql['where'], array($element . '_id' => '', 'confirm' => '')))) == 0) {
                $s3ql['where']['deployment_id'] = substr($GLOBALS['Did'], 1, strlen($GLOBALS['Did']));
                $info[$GLOBALS['Did']] = URI($GLOBALS['Did'], $user_id, $db);
                $permission2delete[$GLOBALS['Did']] = $info[$GLOBALS['Did']]['delete_data'];
                $core_score[$GLOBALS['Did']] = 8;
                #if(ereg('user|group', $element) && )
                #$s3ql['flag']='resource'; #delete just the resource 'user', 'group' or 'project';
            }
            #echo '<pre>';print_r($s3ql);exit;
            if (ereg('(user|group|project|collection|rule|item|statement|file|permission)', $element)) {
                foreach ($deleteable as $s3element => $id) {
                    #echo $s3element;
                    if ($s3ql['where'][$id] != '') {
                        #for this, this will allow removing 1 permission at a time.
                        $element_name = $s3element;
                        $id_name = $id;
                        $uid4info = uid($s3ql['where'][$id]);
                        #if(!ereg('^(U|G|P|C|I|S|R)', $letter))
                        $uid4info['uid'] = strtoupper(substr($element_name, 0, 1)) . $uid4info['uid'];
                        $uid2check = $uid4info['uid'];
                        $element_info = URIinfo($uid2check, $user_id, $key, $db);
                        $info[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = $element_info;
                        $permission2delete[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = $element_info['delete_data'];
                        $core_score[strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name]] = $scoreTable[$element_name];
                        #when deleting a rule on a project, user does not need to be able to change the rule, he only needs to be able to change project.
                        #$core_score =
                        if (!is_array($element_info)) {
                            if ($uid4info['Did'] == $GLOBALS['Did']) {
                                return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'Resource ' . strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name] . ' was not found', $format, '');
                            }
                        }
                    }
                }
                #echo '<pre>';print_r($info);exit;
            }
            #if user is unlinking a resource from another, he needs permission on the upstream one,
            #for example, owner of a porject that is deleting a rule from a project. The owner of the project who does not want to share the rule anymore should instead remove grant permissions from it. Similar as in "insert", but the other way around
            #the simplest case is when a user is "removing himself" from a resource - that is when flag is standard and there is only 1 s3id.
            #echo '<pre>';print_r($core_score);exit;
            if (ereg('(user|group|project|collection|rule|item|statement|file)', $element)) {
                if (count($core_score) == '1' || count($core_score) == '2' && $info[$GLOBALS['Did']] != '') {
                    $s3ql['flag'] = $s3ql['flag'] != '' ? $s3ql['flag'] : 'all';
                    #$uid2delete = key($permission2delete);
                    #when user requests to be removed from a resource, remove resource and all dependencies where user has access.
                    $children = array('deployment' => array('project', 'user', 'group'), 'user' => array(), 'group' => array(), 'project' => array('rule', 'collection'), 'rule' => array('statement'), 'collection' => array('item'), 'item' => array('statement'), 'statement' => array());
                    #even though deleting rule would mean deleting all statements on this class, permission on all statements must be verified as it is downstram
                    #while there are children, build dependencies. Some resources have + 1 child
                    $dependencies = array();
                    foreach ($children[$element] as $child) {
                        $Ds3ql = compact('user_id', 'db');
                        $Ds3ql['from'] = $child;
                        $Ds3ql['where'][$element . '_id'] = $element_id;
                        $tmp = S3QLaction($Ds3ql);
                        if (is_array($tmp)) {
                            $dep_resource[$child] = $tmp;
                        }
                        if (is_array($dep_resource[$child])) {
                            foreach ($dep_resource[$child] as $key => $Dinfo) {
                                $dep_key = strtoupper(substr($child, 0, 1)) . $Dinfo[$GLOBALS['s3ids'][$child]];
                                $info[$dep_key] = $Dinfo;
                                $dependencies[$dep_key] = $Dinfo;
                                #when deleitng any element the parent_id in this case will be the id we are trying to delete
                                if (!empty($children[$child])) {
                                    $Gs3ql = compact('user_id', 'db');
                                    $Gs3ql['from'] = $children[$child][0];
                                    $Gs3ql['where'][$child . '_id'] = $Dinfo[$child . '_id'];
                                    $tmp = S3QLaction($Gs3ql);
                                    if (is_array($tmp)) {
                                        $dep_resource[$children[$child][0]] = $tmp;
                                    }
                                }
                            }
                        }
                    }
                    #to avoid key = 0 on change, push the array 1 element forward.
                    $delete = array();
                    if (is_array($dependencies) && !empty($dependencies)) {
                        $delete = array_map('grab_delete', $dependencies);
                        $delete = array_combine(array_keys($dependencies), $delete);
                    }
                    #echo '<pre>';print_r($dep_resource);exit;
                    switch ($s3ql['flag']) {
                        case 'unlink':
                            #unlink from where?
                            $tounlink = array_filter(array_diff_key($s3ql['where'], array($GLOBALS['COREids'][$element] => '')));
                            if ($s3ql['where']['user_id'] != '') {
                                #remove another user
                                if (max($permission2delete) != '0') {
                                    $user_to_remove = $s3ql['where']['user_id'];
                                } else {
                                    return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to remove user ' . $s3ql['where']['user_id'] . ' from resource ' . key($permission2delete), $format, '');
                                    #return ($no_permission_message.'<message>User does not have permission to remove user '.$s3ql['where']['user_id'].' from resource '.key($permission2delete).'</message>');
                                }
                            } else {
                                $user_to_remove = $user_id;
                            }
                            #remove user from every dependency
                            foreach ($delete as $uid_depend => $allowed) {
                                #being allowed here is only going to affect removing another user that is not "self" from a resource
                                $dep_permission_info = array('uid' => $uid_depend, 'shared_with' => 'U' . $user_to_remove, 'permission_level' => '000');
                                if ($user_to_remove == $user_id && has_permission($dep_permission_info, $db) != '') {
                                    if (delete_permission(array('permission_info' => $dep_permission_info, 'db' => $db, 'info' => $info))) {
                                        #$output .= $success.'<message>User '.$user_to_remove.' removed from resource '.$uid_depend.'.</message><br>';
                                        $output .= formatReturn($GLOBALS['error_codes']['success'], 'User ' . $user_to_remove . ' removed from resource ' . $uid_depend, $format, '');
                                    }
                                } elseif ($user_to_remove != $user_id && $allowed && has_permission($dep_permission_info) != '') {
                                    if (delete_permission(array('permission_info' => $dep_permission_info, 'db' => $db, 'info' => $info))) {
                                        #$output .= $success.'<message>User '.$user_to_remove.' removed from resource '.$uid_depend.'.</message><br>';
                                        $output .= formatReturn($GLOBALS['error_codes']['success'], 'User ' . $user_to_remove . ' removed from resource ' . $uid_depend, $format, '');
                                    }
                                } elseif ($user_to_remove != $user_id && !$allowed) {
                                    #$output .= $success.'<message>User does not have permission to remove'.$user_to_remove.' from resource '.$uid_depend.'.</message><br>';
                                    $output .= formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to remove' . $user_to_remove . ' from resource ' . $uid_depend, $format, '');
                                }
                            }
                            #now remove the resource from user
                            $shared_with = array_search(max($core_score), $core_score);
                            $uid2remove = str_replace($GLOBALS['Did'] . '/', '', $uid);
                            if (ereg('^D', $shared_with)) {
                                #when shared_with is deploymet, we reach the highest level: remove user from tables.
                                deleteCoreResource($uid2remove, $user_id, $db);
                                insertLogs($uid2remove, $info, $user_id, $db);
                            }
                            #$uid = array_search(min($core_score), $core_score);
                            $permission_info = array('uid' => $uid2remove, 'shared_with' => 'U' . $user_to_remove, 'permission_level' => '000', 'info' => $info);
                            $has_permission = has_permission($permission_info, $db);
                            if ($has_permission != '' && $has_permission != '000') {
                                $done = delete_permission(compact('permission_info', 'db', 'user_id', 'info'));
                            } elseif ($has_permission == '') {
                                $done = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
                            }
                            if ($done || $has_permission == '000') {
                                $output .= formatReturn($GLOBALS['error_codes']['success'], 'User ' . $user_to_remove . ' removed from resource ' . key($permission2delete) . '.', $s3ql['format'], '');
                            } else {
                                $output .= formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'User ' . $user_to_remove . ' was NOT removed from resource ' . key($permission2delete), $s3ql['format'], '');
                            }
                            $return_message = $output;
                            break;
                        case 'resource':
                            $uid2remove = str_replace($GLOBALS['Did'] . '/', '', $uid);
                            if (max($permission2delete) == '0') {
                                return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to remove user ' . $s3ql['where']['user_id'] . ' from resource ' . key($permission2delete) . ' If you want to remove this resource from view use flag "unlink"', $format, '');
                            } else {
                                #when user is actually deleting a resource, he must have "change" permission on it. He does not need "change" permission on all dependencies.
                                if (deleteCoreResource($uid2remove, $user_id, $db)) {
                                    $return_message = formatReturn($GLOBALS['error_codes']['success'], 'Resource ' . $uid . ' deleted. Resources that depend on ' . $uid . ' may still exist', $format, '');
                                    #if($s3ql['format']=='')
                                    #$return_message = ('<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '',$GLOBALS['messages']['success']).'</TD><TD>Resource '.$uid.' deleted. Resources that depend on '.$uid.' may still exist</TD></TR></TABLE>');
                                    #else
                                    #$return_message =  ($success.'<message>Resource '.$uid.' deleted. Resources that depend on '.$uid.' may still exist</message>');#not a hard core delete.
                                    insertLogs($uid, $info, $user_id, $db);
                                }
                            }
                            break;
                        case 'all':
                            if (max($permission2delete) == '0') {
                                return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to delete ' . $s3ql['where']['user_id'] . ' If you intend to remove this resource from your projects use flag "unlink"', $format, '');
                            } else {
                                #echo '<pre>';print_r($delete);exit;
                                #start deleting dependencies
                                foreach ($delete as $uid_depend => $allowed) {
                                    $permission_info = array('uid' => $uid_depend, 'shared_with' => 'U' . $user_id, 'permission_level' => '000');
                                    if ($allowed) {
                                        if (deleteCoreResource($uid_depend, $user_id, $db)) {
                                            $output .= formatReturn($GLOBALS['error_codes']['success'], '' . $uid_depend . ' deleted', $s3ql['format'], '');
                                            #if($s3ql['format']=='')
                                            #$output .= '<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '',$GLOBALS['messages']['success']).'</TD><TD>'.$uid_depend.' deleted</TD></TR></TABLE>';
                                            #else
                                            #$output .= $success.'<message>'.$uid_depend.' deleted</message><br>';
                                        } elseif (has_permission($permission_info, $db) != '') {
                                            if (delete_permission(compact('permission_info', 'db', 'user_id', 'info'))) {
                                                $output .= $success . '<message>Permission on ' . $uid_depend . ' removed for ' . $user_id . '</message><br>';
                                            }
                                        }
                                    }
                                    #echo '<pre>';print_r($info);exit;
                                    insertLogs($uid_depend, $info, $user_id, $db);
                                }
                                #Now delete everything that shared this collection in permission tables
                                $uid_info = uid($uid);
                                $sql = "delete from s3db_permission where uid = '" . $uid . "' or shared_with = '" . $uid . "'";
                                #echo $sql;exit;
                                $db->query($sql, __LINE__, __FILE__);
                                #and now delete the resource itseld
                                $uid = strtoupper(substr($element, 0, 1)) . $element_id;
                                if (deleteCoreResource($uid, $user_id, $db)) {
                                    $output .= formatReturn($GLOBALS['error_codes']['success'], $uid . ' deleted', $s3ql['format'], '');
                                    insertLogs($uid, $info, $user_id, $db);
                                } else {
                                    $output .= $something_went_wrong . '<message>Could not delete ' . $uid . '</message>';
                                }
                                $return_message = $output;
                            }
                            break;
                    }
                } elseif (count($core_score) > 1) {
                    if (ereg('^G', array_search(max($core_score), $core_score)) && array_search(min($core_score), $core_score) == 'U' . $user_id) {
                        $permission2delete[array_search(max($core_score), $core_score)] = '1';
                    }
                    #if the user is removing himself from group
                    if (max($permission2delete) == '0') {
                        return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to remove user ' . $s3ql['where']['user_id'] . ' from resource ' . key($permission2delete) . ' If you want to remove this resource from view use flag "unlink"', $format, '');
                    }
                    #can only pass if the user has access to remove data from the highest scored
                    $result = array_combine($core_score, $permission2delete);
                    #score as index and permissions as values
                    #a group and a user can be inserted in any one resource... as long as user does have permission on the resource
                    if (ereg('user|group', $element) && $result[min(array_keys($result))]) {
                        $result[max(array_keys($result))] = '1';
                    }
                    $double_permission = array('statement' => array('2', '4'));
                    #2 and 4 are the scores the statement needs in the score: rules and instances
                    if (in_array($element, array_keys($double_permission)) && min(array($result[$double_permission[$element][0]], $result[$double_permission[$element][1]])) == '0') {
                        $result = array_combine(array($double_permission[$element][0], $double_permission[$element][1]), array('0', '0'));
                    }
                    #result only checks upstream permissions, but is idB allowed to insert itself on idA?
                    if ($result[max(array_keys($result))] == '0') {
                        #this means the highest scored element does NOT have permission to delete
                        $ids = array_keys($permission2delete);
                        #some ids can be swapped, that is class is swapped with rule "hasUID" and instance is swapped with statement of rule "hasUID"
                        $swap = array('C' => 'rule_id', 'I' => 'statement_id');
                        foreach ($ids as $to_swap) {
                            if (in_array(substr($to_swap, 0, 1), array_keys($swap))) {
                                $letter = substr($to_swap, 0, 1);
                                $new_id = strtoupper(substr($swap[$letter], 0, 1)) . $info[$to_swap][$swap[$letter]];
                            } else {
                                $new_id = $to_swap;
                            }
                            $ids1[] = $new_id;
                        }
                        $ids = $ids1;
                        $recalc_permission2delete = $permission2delete;
                        $has_permission = has_permission(array('uid' => $ids[0], 'shared_with' => $ids[1]), $db);
                        if (ereg('2$', $has_permission) || ereg('1$', $has_permission) && $element_info['created_by'] == $user_id) {
                        }
                        #does the idB have insert permission on idA? Change the score :-)
                        $recalc_permission2delete[$ids[0]] = substr($has_permission, 2, 1);
                        #check again the result
                        $recalc_result = array_combine($core_score, $recalc_permission2delete);
                        #score as index and permissions as values
                        #echo '<pre>';print_r($recalc_result);exit;
                        if ($recalc_result[max(array_keys($recalc_result))] == '0') {
                            return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to delete in resource ' . array_search('0', $permission2delete), $format, '');
                        }
                        #return ($GLOBALS['messages']['no_permission_message'].'<message>User does not have permission to delete in resource '.array_search('0', $permission2delete).'</message>');
                    }
                }
                #still there? Ok, we are ready to remove resource from another resource
                $shared_with = array_search(max($core_score), $core_score);
                $uid = array_search(min($core_score), $core_score);
                $return_message = removePermission(compact('uid', 'shared_with', 'db', 'info', 'user_id'));
                insertLogs($uid, $info, $user_id, $db);
                return $return_message;
            }
            #begin cases not considered in "deleteable" and those that need extra operations like rule_log and statement_log insertions
            switch ($element) {
                case 'key':
                    #DELETE KEY
                    #does this key belong to this user?
                    if ($user_id != '1' && $e_info['account_id'] != $user_id) {
                        return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'This key cannot be deleted', $format, '');
                        #return $no_permission_message."<message>This key cannot be deleted</message>";
                    }
                    $D['table'] = 'access_keys';
                    $D['element'] = 'key';
                    $D['element_id'] = $element_id;
                    $deleted = delete_element($D);
                    if ($deleted) {
                        return formatReturn($GLOBALS['error_codes']['success'], $element . " " . $element_id . " deleted", $format, '');
                        #$output .= $success;
                        #$output .= $element." deleted<BR>";
                        #$query = S3QLRestWrapper(array('key'=>$key));
                        #$output .= '<a href =" '.$query['url'].$query['s3ql'].'<select>*</select><from>'.$element.'s</from></S3QL>">List '.$element.'s</a>';
                        #return ($output);
                    } else {
                        return formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Failed to delete key", $format, '');
                    }
                    break;
                case 'permission':
                    #DELETE PERMISSION
                    #permission to delete this permission was checked before switch
                    #it will delete permission from downstream resources via upstream but NOT the other way around.
                    $permission_info['shared_with'] = $s3ql['where']['user_id'] != '' ? 'U' . $s3ql['where']['user_id'] : array_search(max($core_score), $core_score);
                    $permission_info['uid'] = array_search(min($core_score), $core_score);
                    #delete only if user has permission to change.
                    $me = array('uid' => $permission_info['uid'], 'shared_with' => 'U' . $user_id, 'db' => $db, 'user_id' => $user_id);
                    $meOnUid = permission4resource($me);
                    $tmp = permission_level($meOnUid, $permission_info['uid'], $user_id, $db);
                    if (!$tmp['edit']) {
                        return formatReturn($GLOBALS['error_codes']['no_permission_message'], "User does not have permission to change " . $permission_info['uid'], $s3ql['format'], '');
                    }
                    if (delete_permission(compact('permission_info', 'db', 'info', 'user_id'))) {
                        insertLogs($permission_info['uid'], $info, $user_id, $db);
                        return formatReturn($GLOBALS['error_codes']['success'], 'Permission on ' . $permission_info['uid'] . ' removed', $format, '');
                    }
                case 'rule':
                    insert_rule_log(array('action' => 'delete', 'rule_info' => $info['R' . $element_id], 'oldvalues' => $info['R' . $element_id], 'inputs' => array(), 'db' => $db, 'user_id' => $user_id));
                    break;
                case 'statement':
                    break;
                case 'class':
                    break;
            }
            #finish switch eleent
            #finish delete
        #finish delete
        case 'grant':
            $permission_info['permission_level'] = $s3ql['grant'];
            $shareables = array('project' => 'project_id', 'rule' => 'rule_id', 'class' => 'class_id', 'instance' => 'instance_id', 'statement' => 'statement_id');
            $shared_with = array('project' => 'project_id', 'user' => 'user_id', 'group' => 'group_id');
            foreach ($shareables as $name => $id) {
                if ($s3ql['where'][$id] != '') {
                    $element_name = $name;
                    $id_name = $id;
                    $permission_info['uid'] = strtoupper(substr($name, 0, 1)) . $s3ql['where'][$id];
                    $permission_info['id'] = $s3ql['where'][$id];
                }
            }
            foreach ($shared_with as $name1 => $id1) {
                if ($s3ql['where'][$id1] != '') {
                    $element_name1 = $name1;
                    $id_name1 = $id1;
                    $permission_info['shared_with'] = strtoupper(substr($name1, 0, 1)) . $s3ql['where'][$id1];
                }
            }
            $permission_info['uid'] = $s3ql['on'] != '' ? $s3ql['on'] : ($permission_info['uid'] != '' ? $permission_info['uid'] : '');
            $permission_info['shared_with'] = $s3ql['to'] != '' ? $s3ql['to'] : ($permission_info['shared_with'] != '' ? $permission_info['shared_with'] : '');
            $permission_info['id'] = substr($permission_info['uid'], 1, strlen($permission_info['uid']));
            $info[$permission_info['uid']] = URI($permission_info['uid'], $user_id, $db);
            $info[$permission_info['shared_with']] = URI($permission_info['shared_with'], $user_id, $db);
            #validate the inputs
            $validity = validate_permission(compact('permission_info', 'user_id', 'db', 'info'));
            switch ($validity) {
                case 0:
                    #lets insert it
                    if (insert_permission(compact('permission_info', 'db', 'user_id', 'info', 'info'))) {
                        #if this the operation of sharing a rule by the owner of the rule. To remove later
                        if (ereg('^R', $permission_info['uid']) && ereg('^P', $permission_info['shared_with']) && !ereg('^0', $permission_info['permission_level'])) {
                            $res3ql = compact('user_id', 'db');
                            $res3ql['insert'] = 'rule';
                            $res3ql['where']['project_id'] = substr($permission_info['shared_with'], 1, strlen($permission_info['shared_with']));
                            $res3ql['where']['rule_id'] = substr($permission_info['uid'], 1, strlen($permission_info['uid']));
                            #$done = S3QLaction($s3ql);
                        }
                    }
                    return formatReturn($GLOBALS['error_codes']['success'], $permission_info['uid'] . ' was shared with ' . $permission_info['shared_with'] . ' with permission level ' . $permission_info['permission_level'], $format, '');
                    #return ($success.'<message>'.$permission_info['uid'].' was shared with '.$permission_info['shared_with'].' with permission level '.$permission_info['permission_level'].'</message>');
                    break;
                case 1:
                    return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Please provide a 2 or 3 digit (range 0-2) permission_level value for this user:view/update/insert permission.' . $GLOBALS['messages']['syntax_message'], $format, '');
                    #return ($wrong_input.'<message>Please provide a 2 or 3 digit (range 0-2) permission_level value for this user:view/update/insert permission.'.$GLOBALS['messages']['syntax_message'].'</message>');
                    break;
                case 2:
                    #This means an update and not an insert is in order
                    if (update_permission(compact('permission_info', 'db', 'user_id', 'info'))) {
                        #if this the operation of sharing a rule -by the owner of the rule. To remove later
                        if (ereg('^R', $permission_info['uid']) && ereg('^P', $permission_info['shared_with']) && !ereg('^0', $permission_info['permission_level'])) {
                            #insert_rule_remotelly(array('project_id'=>$permission_info, 'rule_id'=>, 'db'=>$db));
                            $res3ql = compact('user_id', 'db');
                            $res3ql['insert'] = 'rule';
                            $res3ql['where']['project_id'] = substr($permission_info['shared_with'], 1, strlen($permission_info['shared_with']));
                            $res3ql['where']['rule_id'] = substr($permission_info['uid'], 1, strlen($permission_info['uid']));
                            #$done = S3QLaction($res3ql);
                        }
                    }
                    return formatReturn($GLOBALS['error_codes']['success'], $permission_info['uid'] . ' was shared with ' . $permission_info['shared_with'] . ' with permission level ' . $permission_info['permission_level'], $format, '');
                    #return ($success.'<message>'.$permission_info['uid'].' was shared with '.$permission_info['shared_with'].' with permission level '.$permission_info['permission_level'].'</message>');
                    break;
                case 3:
                    return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Numeric part of uid must match id', $format, '');
                    #return ($wrong_input.'<message>numeric part of uid must match id</message>');
                    break;
                case 4:
                    return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], $permission_info['shared_with'] . ' was not found', $format, '');
                    break;
                case 5:
                    return formatReturn($GLOBALS['error_codes']['something_does_not_exist'], $permission_info['uid'] . ' was not found', $format, '');
                    break;
                case 6:
                    return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'Please chose a level of permission that is equal or smaller than ' . $element_info['permission_level'] . '.', $format, '');
                    break;
                case 7:
                    return formatReturn($GLOBALS['error_codes']['wrong_input'], 'Permission cannot be specified on collection (C) or item (I)', $format, '');
                    break;
                case 8:
                    return formatReturn($GLOBALS['error_codes']['wrong_input'], 'uid to share or user to share with is empty', $format, '');
                    break;
            }
    }
    #close switch action
}
Ejemplo n.º 9
0
 do_log("Nodes possible to register:" . $fs, 'v', __FILE__, __FUNCTION__, __LINE__);
 $myip4 = get_ip(4);
 $conti = false;
 foreach ($dbconfig['ecallmgr']->default->fs_nodes as $key => $nam) {
     $name = explode("@", $nam);
     if (gethostbyname($name[1]) == $myip4) {
         $conti = 1;
         $match = $key;
     }
 }
 if ($conti) {
     do_log("Our part of {$fs} is " . $dbconfig['ecallmgr']->default->fs_nodes[$match], 'v', __FILE__, __FUNCTION__, __LINE__);
     $ret = get_all_dbs($host);
     foreach ($ret['res'] as $key => $value) {
         if (stristr($value, 'numbers/')) {
             $res = get_entry($value, '/_design/numbers/_view/regexternal_modified');
             if ($res['err']) {
                 do_log("Get regexternal_view Error:" . $res['err']);
                 continue;
             } else {
                 foreach ($res['res']->rows as $num) {
                     $num->value->db = $value;
                     $result[$num->id] = $num->value;
                 }
             }
         }
     }
     foreach ($result as $value) {
         try {
             if (@$value->regextern->pvt_changed == false) {
                 $value->regextern->pvt_changed = 0;
Ejemplo n.º 10
0
function S3QLquery2($s3ql)
{
    #Function S3QLSyntax builds the S3QL query for any remote uri
    #INPUT: $s3ql is an array with at least key
    #OUTPUT: a string, containing the URI with the information on the input element UID
    if ($s3ql['url'] == '') {
        if ($_SERVER['HTTP_X_FORWARDED_HOST'] != '') {
            $s3ql['url'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
        } else {
            $s3ql['url'] = $_SERVER['HTTP_HOST'];
        }
    }
    #when a key is not provided, then assume the user has a remote key that corresponds to the local key
    if ($s3ql['key'] == '') {
        $s3ql['key'] = get_entry('access_keys', 'key_id', 'account_id', $s3ql['user_id'], $s3ql['db']);
    }
    $wrap .= $s3ql['url'] . '/S3QL.php?query=';
    $wrap .= '<S3QL>';
    $wrap .= '<key>' . $s3ql['key'] . '</key>';
    #remove the elements already used to build the query, keep the rest
    $s3ql = array_diff_key($s3ql, array('url' => '', 'key' => '', 'user_id' => '', 'db' => ''));
    foreach ($s3ql as $field => $value) {
        if (!is_array($s3ql[$field])) {
            #if is not an array, just build the simple xml
            $wrap .= '<' . $field . '>' . $s3ql[$field] . '</' . $field . '>';
        } else {
            $wrap .= '<' . $field . '>';
            foreach ($value as $subfield => $subvalue) {
                $wrap .= '<' . $subfield . '>' . $subvalue . '</' . $subfield . '>';
            }
            $wrap .= '</' . $field . '>';
        }
    }
    $wrap .= '</S3QL>';
    return $wrap;
}
Ejemplo n.º 11
0
function backup($db_a, $dir)
{
    // get_all_docs
    $dbs = get_entry($db_a, '/_all_docs');
    $dbs = json_decode(json_encode($dbs['res']->rows), true);
    foreach ($dbs as $k => $db) {
        $data = get_entry($db_a, "/" . urlencode($db['id']));
        file_put_contents($dir . urlencode($db['id']), json_encode($data['res']));
    }
    return "backup db->file finished\n";
}
Ejemplo n.º 12
0
function access_key_exists($input_key, $db)
{
    #$found_request = find_entry('access_keys', '*', 'key_id', array('key_id'=>$input_key, 'db'=>$db));
    $found_request = get_entry('access_keys', 'account_id', 'key_id', $input_key, $db);
    if ($found_request != '') {
        return True;
    } else {
        return False;
    }
}
Ejemplo n.º 13
0
 // min seconds for core reload (because don't to quickly reload the core)
 $fs = count($dbconfig->default->fs_nodes);
 do_log("Nodes possible to register:" . $fs, 'v', __FILE__, __FUNCTION__, __LINE__);
 $myip4 = get_ip(4);
 $conti = false;
 foreach ($dbconfig->default->fs_nodes as $key => $nam) {
     $name = explode("@", $nam);
     if (gethostbyname($name[1]) == $myip4) {
         $conti = 1;
         $match = $key;
     }
 }
 if ($conti) {
     do_log("Our part of {$fs} is " . $dbconfig->default->fs_nodes[$match], 'v', __FILE__, __FUNCTION__, __LINE__);
     // get all reged nodes in this cluster
     $res = get_entry('servers', '/_design/servers/_view/cluster_healthy');
     if ($res['err']) {
         do_log("Get cluster_healthy_view Error:" . $res['err']);
         continue;
     } else {
         foreach ($res['res']->rows as $num) {
             $num->value->db = $value;
             $result[$num->id] = $num->value;
         }
     }
     foreach ($result as $value) {
         do_log("Extension:" . $value->regextern->extension . " (" . $value->regextern->pvt_modified . " >= " . $value->regextern->pvt_changed . " && " . $value->active . " == true &&  " . $value->state . " == 'in_service')", 'd', __FILE__, __FUNCTION__, __LINE__);
         if ($value->regextern->pvt_modified >= $value->regextern->pvt_changed && $value->active == true && $value->state == 'in_service') {
             write_xml($value);
             $reload = true;
         } elseif ($value->modified >= $value->changed && $value->active == false) {
Ejemplo n.º 14
0
function get_entry_by_code($code)
{
    global $index_count, $entry;
    $index_count = 0;
    do {
        $ok = get_entry();
        echo ".";
        if ($entry['code'] == $code) {
            return true;
        }
    } while ($ok);
    return false;
}
Ejemplo n.º 15
0
function send_emails($id_comment)
{
    // disposant de l'email d'un commentaire, on détermine l'article associé, le titre, l’auteur du comm et l’email de l’auteur du com.
    $article = get_entry($GLOBALS['db_handle'], 'commentaires', 'bt_article_id', $id_comment, 'return');
    $article_title = get_entry($GLOBALS['db_handle'], 'articles', 'bt_title', $article, 'return');
    $comm_author = get_entry($GLOBALS['db_handle'], 'commentaires', 'bt_author', $id_comment, 'return');
    $comm_author_email = get_entry($GLOBALS['db_handle'], 'commentaires', 'bt_email', $id_comment, 'return');
    // puis la liste de tous les commentaires de cet article
    $liste_commentaires = array();
    try {
        $query = "SELECT bt_email,bt_subscribe,bt_id FROM commentaires WHERE bt_statut=1 AND bt_article_id=? ORDER BY bt_id";
        $req = $GLOBALS['db_handle']->prepare($query);
        $req->execute(array($article));
        $liste_commentaires = $req->fetchAll(PDO::FETCH_ASSOC);
    } catch (Exception $e) {
        die('Erreur : ' . $e->getMessage());
    }
    // Récupérre la liste (sans doublons) des emails des commentateurs, ainsi que leurs souscription à la notification d'email.
    // si plusieurs comm avec la même email, alors seul le dernier est pris en compte.
    // si l’auteur même du commentaire est souscrit, il ne recoit pas l’email de son propre commentaire.
    $emails = array();
    foreach ($liste_commentaires as $i => $comment) {
        if (!empty($comment['bt_email']) and $comm_author_email != $comment['bt_email']) {
            $emails[$comment['bt_email']] = $comment['bt_subscribe'] . '-' . get_id($comment['bt_id']);
        }
    }
    // ne conserve que la liste des mails dont la souscription est demandée (= 1)
    $to_send_mail = array();
    foreach ($emails as $mail => $is_subscriben) {
        if ($is_subscriben[0] == '1') {
            // $is_subscriben is seen as a array of chars here, first char is 0 or 1 for subscription.
            $to_send_mail[$mail] = substr($is_subscriben, -14);
        }
    }
    $subject = 'New comment on "' . $article_title . '" - ' . $GLOBALS['nom_du_site'];
    $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset="UTF-8"' . "\r\n";
    $headers .= 'From: no.reply_' . $GLOBALS['email'] . "\r\n" . 'X-Mailer: BlogoText - PHP/' . phpversion();
    // for debug
    //header('Content-type: text/html; charset=UTF-8');
    //die(($to. $subject. $message. $headers));
    //echo '<pre>';print_r($emails);
    //echo '<pre>';print_r($to_send_mail);
    //die();
    // envoi les emails.
    foreach ($to_send_mail as $mail => $is_subscriben) {
        $comment = substr($is_subscriben, -14);
        $unsublink = get_blogpath($article, '') . '&amp;unsub=1&amp;comment=' . $comment . '&amp;mail=' . sha1($mail);
        $message = '<html>';
        $message .= '<head><title>' . $subject . '</title></head>';
        $message .= '<body><p>A new comment by <b>' . $comm_author . '</b> has been posted on <b>' . $article_title . '</b> form ' . $GLOBALS['nom_du_site'] . '.<br/>';
        $message .= 'You can see it by following <a href="' . get_blogpath($article, '') . '#' . article_anchor($id_comment) . '">this link</a>.</p>';
        $message .= '<p>To unsubscribe from the comments on that post, you can follow this link: <a href="' . $unsublink . '">' . $unsublink . '</a>.</p>';
        $message .= '<p>To unsubscribe from the comments on all the posts, follow this link: <a href="' . $unsublink . '&amp;all=1">' . $unsublink . '&amp;all=1</a>.</p>';
        $message .= '<p>Also, do not reply to this email, since it is an automatic generated email.</p><p>Regards.</p></body>';
        $message .= '</html>';
        mail($mail, $subject, $message, $headers);
    }
    return TRUE;
}
Ejemplo n.º 16
0
function afficher_calendrier()
{
    // article
    if (isset($_GET['d']) and preg_match('#^\\d{4}(/\\d{2}){5}#', $_GET['d'])) {
        $id = substr(str_replace('/', '', $_GET['d']), 0, 14);
        $date = substr(get_entry($GLOBALS['db_handle'], 'articles', 'bt_date', $id, 'return'), 0, 8);
        $date = (preg_match('#^\\d{4}(/\\d{2}){5}#', $date) and $date <= date('Y/m/d/H/i/s')) ? $date : date('Ym');
    } elseif (isset($_GET['d']) and preg_match('#^\\d{4}/\\d{2}(/\\d{2})?#', $_GET['d'])) {
        $date = str_replace('/', '', $_GET['d']);
        $date = preg_match('#^\\d{6}\\d{2}#', $date) ? substr($date, 0, 8) : substr($date, 0, 6);
        // avec jour ?
    } elseif (isset($_GET['id']) and preg_match('#^\\d{14}#', $_GET['id'])) {
        $date = substr($_GET['id'], 0, 8);
    } else {
        $date = date('Ym');
    }
    $annee = substr($date, 0, 4);
    $ce_mois = substr($date, 4, 2);
    $ce_jour = strlen(substr($date, 6, 2)) == 2 ? substr($date, 6, 2) : '';
    $qstring = (isset($_GET['mode']) and !empty($_GET['mode'])) ? 'mode=' . htmlspecialchars($_GET['mode']) . '&amp;' : '';
    $jours_semaine = array($GLOBALS['lang']['lu'], $GLOBALS['lang']['ma'], $GLOBALS['lang']['me'], $GLOBALS['lang']['je'], $GLOBALS['lang']['ve'], $GLOBALS['lang']['sa'], $GLOBALS['lang']['di']);
    $premier_jour = mktime('0', '0', '0', $ce_mois, '1', $annee);
    $jours_dans_mois = date('t', $premier_jour);
    $decalage_jour = date('w', $premier_jour - '1');
    $prev_mois = basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . $annee . '/' . str2($ce_mois - 1);
    if ($prev_mois == basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . $annee . '/' . '00') {
        $prev_mois = basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . ($annee - '1') . '/' . '12';
    }
    $next_mois = basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . $annee . '/' . str2($ce_mois + 1);
    if ($next_mois == basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . $annee . '/' . '13') {
        $next_mois = basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . ($annee + '1') . '/' . '01';
    }
    // On verifie si il y a un ou des articles/liens/commentaire du jour dans le mois courant
    $tableau = array();
    $mode = !empty($_GET['mode']) ? $_GET['mode'] : 'blog';
    switch ($mode) {
        case 'comments':
            $where = 'commentaires';
            break;
        case 'links':
            $where = 'links';
            break;
        case 'blog':
        default:
            $where = 'articles';
            break;
    }
    $tableau = table_list_date($annee . $ce_mois, 1, $where);
    $html = '<table id="calendrier">' . "\n";
    $html .= '<caption>';
    if ($annee . $ce_mois > $GLOBALS['date_premier_message_blog']) {
        $html .= '<a href="' . $prev_mois . '">&#171;</a>&nbsp;';
    }
    // Si on affiche un jour on ajoute le lien sur le mois
    $html .= '<a href="' . basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . $annee . '/' . $ce_mois . '">' . mois_en_lettres($ce_mois) . ' ' . $annee . '</a>';
    // On ne peut pas aller dans le futur
    if ($ce_mois != date('m') || $annee != date('Y')) {
        $html .= '&nbsp;<a href="' . $next_mois . '">&#187;</a>';
    }
    $html .= '</caption>' . "\n" . '<tr>' . "\n";
    if ($decalage_jour > 0) {
        for ($i = 0; $i < $decalage_jour; $i++) {
            $html .= '<td></td>';
        }
    }
    // Indique le jour consulte
    for ($jour = 1; $jour <= $jours_dans_mois; $jour++) {
        if ($jour == $ce_jour) {
            $class = ' class="active"';
        } else {
            $class = '';
        }
        if (in_array($jour, $tableau)) {
            $lien = '<a href="' . basename($_SERVER['PHP_SELF']) . '?' . $qstring . 'd=' . $annee . '/' . $ce_mois . '/' . str2($jour) . '">' . $jour . '</a>';
        } else {
            $lien = $jour;
        }
        $html .= '<td' . $class . '>';
        $html .= $lien;
        $html .= '</td>';
        $decalage_jour++;
        if ($decalage_jour == 7) {
            $decalage_jour = 0;
            $html .= '</tr>';
            if ($jour < $jours_dans_mois) {
                $html .= '<tr>';
            }
        }
    }
    if ($decalage_jour > 0) {
        for ($i = $decalage_jour; $i < 7; $i++) {
            $html .= '<td> </td>';
        }
        $html .= '</tr>' . "\n";
    }
    $html .= '</table>' . "\n";
    return $html;
}
Ejemplo n.º 17
0
 function the_entry($thisentry, $link = true, $excerpt = false, $current_user = '')
 {
     echo get_entry($thisentry, $link, $excerpt, $current_user);
 }
Ejemplo n.º 18
0
function upload_phone_data($prov, $db_a = 'brand_provisioner', $type = false)
{
    global $sag;
    $prov['_id'] = 'ui/' . $prov['endpoint_brand'] . "/" . $prov['endpoint_family'] . "/" . $prov['endpoint_model'];
    $obj = $prov;
    $sag->setDatabase($db_a);
    unset($obj->_rev);
    try {
        if (preg_match("/^_/", $prov['_id'])) {
            echo $sag->put($prov['_id'], $obj)->body->ok;
        } else {
            echo $sag->put(urlencode($prov['_id']), $obj)->body->ok;
        }
    } catch (Exception $e) {
        echo $e->getMessage() . "DB:" . $db_a . " file:" . $prov['_id'] . "\n";
    }
    // add to phonetree
    $tree = get_entry($db_a, "/phonetree");
    $new = json_decode(json_encode($tree), true);
    $new['res']['data'][$prov['endpoint_brand']]['id'] = $prov['endpoint_brand'];
    $new['res']['data'][$prov['endpoint_brand']]['name'] = $prov['endpoint_brand'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['id'] = $prov['endpoint_brand'] . "_" . $prov['endpoint_family'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['name'] = $prov['endpoint_family'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['models'][$prov['endpoint_model']]['id'] = $prov['endpoint_brand'] . "_" . $prov['endpoint_model'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['models'][$prov['endpoint_model']]['name'] = $prov['endpoint_model'];
    $new = json_decode(json_encode($new), FALSE);
    $new = (array) $new;
    $new['res']->views++;
    $sag->put("phonetree", $new['res'])->body->ok;
    return 'uploaded';
}
Ejemplo n.º 19
0
function upload_phone_data($prov, $db_a = 'brand_provisioner', $type = false)
{
    global $sag, $HTTP, $host, $dbport;
    $prov['_id'] = urlencode('ui/' . $prov['endpoint_brand'] . "/" . $prov['endpoint_family'] . "/" . $prov['endpoint_model']);
    $obj = $prov;
    $sag->setDatabase($db_a);
    $now = json_decode(file_get_contents($HTTP . $host . ":" . $dbport . "/" . $db_a . "/" . $prov['_id']));
    if ($now->_id == urldecode($prov['_id'])) {
        $obj['_id'] = urlencode($now->_id);
        $obj['_rev'] = $now->_rev;
        $obj['views']++;
        echo "update-" . $obj['endpoint_brand'] . "|" . $obj['endpoint_model'] . ": ";
    } else {
        unset($obj['_rev']);
        echo "create->" . $obj['endpoint_brand'] . "|" . $obj['endpoint_model'] . ": ";
    }
    try {
        if (preg_match("/^_.*/", urldecode($obj['_id']))) {
            echo $sag->put(urldecode($obj['_id']), $obj)->body->ok . "->" . $obj['_id'] . "\n";
        } else {
            echo $sag->put($obj['_id'], $obj)->body->ok . "\n";
        }
    } catch (Exception $e) {
        echo $e->getMessage() . "DB:" . $db_a . " file:" . urlencode($obj['_id']) . "\n";
    }
    // add to phonetree
    $tree = get_entry($db_a, "/phonetree");
    $new = json_decode(json_encode($tree), true);
    $new['res']['data'][$prov['endpoint_brand']]['id'] = $prov['endpoint_brand'];
    $new['res']['data'][$prov['endpoint_brand']]['name'] = $prov['endpoint_brand'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['id'] = $prov['endpoint_brand'] . "_" . $prov['endpoint_family'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['name'] = $prov['endpoint_family'];
    $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['models'][$prov['endpoint_model']]['name'] = $prov['endpoint_model'];
    if ('yealink' == $prov['endpoint_brand']) {
        $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['models'][$prov['endpoint_model']]['id'] = $prov['endpoint_brand'] . "_" . $prov['endpoint_family'] . "_" . $prov['endpoint_model'];
    } else {
        $new['res']['data'][$prov['endpoint_brand']]['families'][$prov['endpoint_family']]['models'][$prov['endpoint_model']]['id'] = $prov['endpoint_brand'] . "_" . $prov['endpoint_model'];
    }
    $new = json_decode(json_encode($new), FALSE);
    $new = (array) $new;
    $new['res']->views++;
    $sag->put("phonetree", $new['res'])->body->ok;
    return 'uploaded';
}
Ejemplo n.º 20
0
        }
    }
} elseif ($key != '') {
    $key_valid = authenticate($key, $url);
    switch ($key_valid) {
        case 0:
            $db = CreateObject('s3dbapi.db');
            $db->Halt_On_Error = 'no';
            $db->Host = $GLOBALS['s3db_info']['server']['db']['db_host'];
            $db->Type = $GLOBALS['s3db_info']['server']['db']['db_type'];
            $db->Database = $GLOBALS['s3db_info']['server']['db']['db_name'];
            $db->User = $GLOBALS['s3db_info']['server']['db']['db_user'];
            $db->Password = $GLOBALS['s3db_info']['server']['db']['db_pass'];
            $db->connect();
            #if user has been authenticated, then fire away! he can see data!!
            $key_info = get_entry('access_keys', 'account_id,uid', 'key_id', $key, $db);
            $user_id = $key_info['account_id'];
            #if no user_id was found, but it was authenticated, then it is a remote login
            $user_info = s3info('user', $user_id, $db);
            #if a uid was specified for this key, s3ql should NOT ALLOW any more queries other than the ones specified in uid
            $args = '?key=' . $key;
            break;
        case 2:
            list($db, $user_info, $user_id) = loginAsPublic();
            break;
        case 1:
            #echo '<message>Key not valid. If this is a remote key, please provide url where user is located (for example: http://mylocalhost/s3db/U4)</message>';
            $format = $_REQUEST['format'];
            if ($format == '') {
                $format = 'html';
            }
Ejemplo n.º 21
0
function delete_entry($entry_id)
{
    $entry = get_entry($entry_id);
    $query = "DELETE FROM entries WHERE entry_id = {$entry_id}";
    if ($result = mysql_query($query)) {
        echo $query;
        log_change(CURRENT_USER, 'removed', $entry['person_id'], 'from', $entry['project_id'], $entry['startdate']);
    } else {
        die("<p>could not delete item because:<br>" . mysql_error() . "<br>the query was {$query}.</p>");
    }
}
Ejemplo n.º 22
0
    echo "Not a valid S3DB call";
    exit;
}
ini_set("include_path", S3DB_SERVER_ROOT . '/pearlib' . PATH_SEPARATOR . ini_get("include_path"));
include_once S3DB_SERVER_ROOT . '/s3dbcore/class.db.inc.php';
include_once S3DB_SERVER_ROOT . '/s3dbcore/common_functions.inc.php';
include_once S3DB_SERVER_ROOT . '/s3dbcore/callback.php';
include_once S3DB_SERVER_ROOT . '/s3dbcore/SQL.php';
include_once S3DB_SERVER_ROOT . '/s3dbcore/display.php';
$inputs = scriptInputs($_REQUEST, $argv);
$db = CreateObject('s3dbapi.db');
$db->Halt_On_Error = 'no';
$db->Host = $GLOBALS['s3db_info']['server']['db']['db_host'];
$db->Type = $GLOBALS['s3db_info']['server']['db']['db_type'];
$db->Database = $GLOBALS['s3db_info']['server']['db']['db_name'];
$db->User = $GLOBALS['s3db_info']['server']['db']['db_user'];
$db->Password = $GLOBALS['s3db_info']['server']['db']['db_pass'];
$db->connect();
$user_id = get_entry('access_keys', 'account_id', 'key_id', $inputs['key'], $db);
if ($user_id == "") {
    $data[0] = array('error_code' => 5, 'message' => 'Key NOT validated', 'user_id' => 'NA');
} elseif ($inputs['user_id'] == "") {
    $data[0] = array('error_code' => 0, 'message' => 'Key successfully validated', 'user_id' => $user_id);
} elseif ($user_id != "" && $user_id == ereg_replace('^U', '', $inputs['user_id'])) {
    $data[0] = array('error_code' => 0, 'message' => 'Key successfully validated', 'user_id' => $user_id);
} else {
    $data[0] = array('error_code' => 5, 'message' => 'Key NOT validated', 'user_id' => 'NA');
}
$cols = array('error_code', 'message', 'user_id');
$format = $inputs['format'];
echo outputFormat(compact('data', 'cols', 'format'));
Ejemplo n.º 23
0
<?php

session_start();
//http://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form
//
include "../../inc/config.php";
include "../../inc/debug-functions.php";
include '../inc/dir-functions.php';
include '../inc/dir-bo-functions.php';
//returns an array
$entry = get_entry($_GET['entryid']);
//pretty($entry);
//get the cateogries available
$cat = get_categories();
//pretty($cat);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Directory Edit| <?php 
echo $tUrl;
?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content = "" />
<link rel="stylesheet" type="text/css" href="../../manage/css/manager.css" />
<script type="text/javascript" src="../../manage/js/tinymce/jscripts/tiny_mce/tiny_mce.js" ></script >
<script type="text/javascript" >
Ejemplo n.º 24
0
     } else {
         $myReturn = update_entry($_POST, false, true);
     }
     break;
 case 'delete_entry':
     $myReturn = delete_entry($_POST);
     break;
 case 'book_entry':
     $myReturn = book_entry($_POST);
     break;
 case 'get_entry':
     $myReturn = get_entry($_POST);
     if (isset($myReturn['minutes_locked']) && $myReturn['minutes_locked'] > 31) {
         $data = array('user_id' => $myReturn['fields']['lock'], 'id' => $myReturn['fields']['id']);
         release_lock($data);
         $myReturn = get_entry($_POST);
     }
     break;
 case 'get_table_data':
     $myReturn = get_table_data($_POST['access_level'] * 1);
     break;
 case 'get_groups':
     $myReturn['groups'] = get_groups($_POST['nuid']);
     break;
 case 'release_lock':
     $myReturn = release_lock($_POST);
     break;
 case 'delete_revisions':
     $myReturn = delete_revisions($_POST);
     break;
 default:
Ejemplo n.º 25
0
function gateway_status_changed($gateway)
{
    global $sag;
    $ret['err'] = false;
    $ret = get_entry('numbers/' . substr($gateway['exten'], 0, 5), urlencode($gateway['exten']));
    if ($ret['err']) {
        do_log("Gateway status change Exten:" . $gateway['exten'] . " Error:" . $ret['err']);
        return false;
    } else {
        $res = $ret['res'];
    }
    $res->regextern->reged_status = $gateway['status'];
    $res->regextern->reged_state = $gateway['state'];
    $res->views++;
    try {
        $sag->setDatabase($res->pvt_db_name);
        $ret['res'] = $sag->put(urlencode($res->_id), $res)->body->ok;
    } catch (Exception $e) {
        $ret['err'] = $e->getMessage() . "DB:{$db}";
    }
}
Ejemplo n.º 26
0
$article_title = '';
// TRAITEMENT
$erreurs_form = array();
if (isset($_POST['_verif_envoi'])) {
    $comment = init_post_comment($_POST['comment_article_id'], 'admin');
    $erreurs_form = valider_form_commentaire($comment, 'admin');
    if (empty($erreurs_form)) {
        traiter_form_commentaire($comment, 'admin');
    }
}
$tableau = array();
// if article ID is given in query string
if (isset($_GET['post_id']) and preg_match('#\\d{14}#', $_GET['post_id'])) {
    $param_makeup['menu_theme'] = 'for_article';
    $article_id = $_GET['post_id'];
    $article_title = get_entry($GLOBALS['db_handle'], 'articles', 'bt_title', $article_id, 'return');
    $query = "SELECT * FROM commentaires WHERE bt_article_id=? ORDER BY bt_id";
    $commentaires = liste_elements($query, array($article_id), 'commentaires');
    $param_makeup['show_links'] = '0';
} else {
    $param_makeup['menu_theme'] = 'for_comms';
    if (!empty($_GET['filtre'])) {
        // for "authors" the requests is "auteur.$search" : here we split the type of search and what we search.
        $type = substr($_GET['filtre'], 0, -strlen(strstr($_GET['filtre'], '.')));
        $search = htmlspecialchars(ltrim(strstr($_GET['filtre'], '.'), '.'));
        // filter for date
        if (preg_match('#^\\d{6}(\\d{1,8})?$#', $_GET['filtre'])) {
            $query = "SELECT c.*, a.bt_title FROM commentaires c LEFT JOIN articles a ON a.bt_id = c.bt_article_id WHERE c.bt_id LIKE ? ORDER BY c.bt_id DESC";
            $commentaires = liste_elements($query, array($_GET['filtre'] . '%'), 'commentaires');
        } elseif ($_GET['filtre'] == 'draft') {
            $query = "SELECT c.*, a.bt_title FROM commentaires c LEFT JOIN articles a ON a.bt_id=c.bt_article_id WHERE c.bt_statut=0 ORDER BY c.bt_id DESC";
Ejemplo n.º 27
0
    $junk = exec("rm -f {$projs2update} {$xml_changes}", $dummy, $rtn);
    if ($rtn != 0) {
        echo "cound not remove files {$projs2update}\nand\n{$xml_changes}\n";
        echo "Please remove them manually";
    }
    exit($diffs_found);
    // should be 0
}
// differences found, save them up in the files.  We only save from
// file 1 as that is the newest file.
write_hdr($Cxml);
while (false != ($f1_line = fgets($F1, 1024))) {
    $proj1 = array();
    if (preg_match('/<project>/', $f1_line)) {
        $m1 = ftell($F1);
        $proj1 = get_entry($F1, $m1);
        //pdbg("DIFFM: P1 Entries:",$proj1);
    } else {
        continue;
    }
    // we now have a project, is it one of the ones that need updating?
    // If so, save it, and record the project name and version.
    $proj_name = xtract($proj1[4]);
    foreach ($adiffs as $name => $version) {
        if ($proj_name == $name) {
            //pdbg("Found $name, saving");
            $Yupdate = "{$name} " . "has a new version:" . " {$version}\n";
            save_Yupdated($P2up, $Yupdate);
            //pdbg("\$proj1 is:", $proj1);
            write_pxml($Cxml, $proj1);
            break;
Ejemplo n.º 28
0
if ($_SERVER['HTTP_X_FORWARDED_HOST'] != '') {
    $def = $_SERVER['HTTP_X_FORWARDED_HOST'];
} else {
    $def = $_SERVER['HTTP_HOST'];
}
if (file_exists('config.inc.php')) {
    include 'config.inc.php';
} else {
    Header('Location: http://' . $def . '/s3db/');
    exit;
}
$key = $_GET['key'];
#Get the key, send it to check validity
include_once 'core.header.php';
if ($key) {
    $user_id = get_entry('access_keys', 'account_id', 'key_id', $key, $db);
} else {
    $user_id = $_SESSION['user']['account_id'];
}
#Universal variables
$sortorder = $_REQUEST['orderBy'];
$direction = $_REQUEST['direction'];
$project_id = $_REQUEST['project_id'];
$uid_info = uid($project_id);
#$acl = find_final_acl($user_id, $project_id, $db);
$project_info = URIinfo('P' . $project_id, $user_id, $key, $db);
$uni = compact('db', 'acl', 'user_id', 'key', 'project_id', 'dbstruct', 'sortorder', 'direction');
#relevant extra arguments
#$args = '?key='.$_REQUEST['key'].'&project_id='.$_REQUEST['project_id'];
#Define the page actions
include 'webActions.php';
#!/usr/bin/php
<?php 
require_once '../config.php';
$host = get_dbhost($hosts);
$sag = new Sag($host, $dbport);
$myip4 = get_ip(4);
$del = ":";
$phone_data = get_entry('brand_provisioner', '/' . urlencode('ui/snom/m3x/m3'));
//print_r($phone_data);
//sleep(88);
$generator = $phone_data['res']->pvt_generator;
// base settings
$read = $generator($phone_data['res']->cfg_base, 'settings');
if ($read) {
    $output .= $read . "\n 1. \n";
}
// behavior settings
$read = $generator($phone_data['res']->cfg_account, 'settings');
if ($read) {
    $output .= $read . "\n 2. \n";
}
// tone settings
$read = $generator($phone_data['res']->cfg_tone, 'settings');
if ($read) {
    $output .= $read . "\n 3. \n";
}
$account = 0;
// keys settings
$read = $generator($phone_data, 'usrkeys', $account);
if ($read) {
    $output .= $read . "\n 4. \n";