Location: PHPKode > projects > cPassMan > cpassman_1.55/groups.php
<?php
####################################################################################################
## File : groups.php
## Author : Nils Laumaillé
## Description : Groups page
## 
## DON'T CHANGE !!!
## 
####################################################################################################
?>
<script src="includes/js/jquery.jeditable.js" type="text/javascript"></script>
<?php
require_once ("sources/NestedTree.class.php");
$tree = new NestedTree($pre.'nested_tree', 'id', 'parent_id', 'title');
$tst = $tree->getDescendants();

//faire une liste des groupes
$liste_groupes = "\'0\':\'".$txt['root']."\'";
foreach($tst as $t){
    if ( in_array($t->id,$_SESSION['groupes_visibles']) ) {
        if ( $t->nlevel == 1 ) $ident = ">";
        if ( $t->nlevel == 2 ) $ident = "->";
        if ( $t->nlevel == 3 ) $ident = "-->";
        if ( $t->nlevel == 4 ) $ident = "--->";
        if ( $t->nlevel == 5 ) $ident = "---->";
        $liste_groupes .= ','."\'".$t->id.'\':\''.$ident." ".addslashes(addslashes($t->title))."\'";
    }
}

//construire la liste des niveaux de complexités
$liste_complexite = "";
foreach($mdp_complexite as $comp){
    if ( empty($liste_complexite) ) $liste_complexite = "\'".$comp[0].'\':\''.$comp[1].'\'';
    else $liste_complexite .= ",\'".$comp[0].'\':\''.$comp[1].'\'';
}

//construire la liste des FONCTIONS
$liste_fonctions = "";
$rows = $db->fetch_all_array("SELECT id, title FROM ".$pre."functions ORDER BY title ASC");
foreach( $rows as $reccord ){
    $liste_fonctions[$reccord['id']] = array('id'=>$reccord['id'],'title'=>$reccord['title']);
}

echo '
<div class="title ui-widget-content ui-corner-all">'.$txt['admin_groups'].'&nbsp;&nbsp;&nbsp;<img src="includes/images/folder--plus.png" id="open_add_group_div" title="'.$txt['item_menu_add_rep'].'" style="cursor:pointer;" /></div>';

echo '
<form name="form_groupes" method="post" action="">
    <div style="width:700px;margin:auto; line-height:20px;">
    <table cellspacing="0" style="margin-top:10px;">
        <thead><tr>
            <th>ID</th>
            <th>'.$txt['group'].'</th>
            <th>'.$txt['complexity'].'</th>
            <th>'.$txt['group_parent'].'</th>
            <th>'.$txt['level'].'</th>
            <th title="'.$txt['group_pw_duration_tip'].'">'.$txt['group_pw_duration'].'</th>
            <th title="'.$txt['del_group'].'"><img src="includes/images/folder--minus.png" /></th>
            <th title="'.$txt['auth_creation_without_complexity'].'"><img src="includes/images/auction-hammer.png" /></th>
            <th title="'.$txt['auth_modification_without_complexity'].'"><img src="includes/images/alarm-clock.png" /></th>
        </tr></thead>
        <tbody>';   
        $x = 0;    
        $arr_ids = array();          
        foreach($tst as $t){
            if ( in_array($t->id,$_SESSION['groupes_visibles']) ) {
                //récup $t->parent_id
                $data = $db->fetch_row("SELECT title FROM ".$pre."nested_tree WHERE id = ".$t->parent_id);
                if ( $t->nlevel == 1 ) {
                    $data[0] = $txt['root'];
                }
                
                //récup les droits associés à ce groupe
                $tab_droits=array();
                $rows = $db->fetch_all_array("SELECT fonction_id  FROM ".$pre."rights WHERE authorized=1 AND tree_id = ".$t->id);
                foreach( $rows as $reccord ){
                    array_push($tab_droits,$reccord['fonction_id']);
                }
                //gérer l'identation en fonction du niveau
                $ident = "";  
                for($l=1;$l<$t->nlevel;$l++) $ident .= "&nbsp;&nbsp;";
                
                //Get some elements from DB concerning this node
                $node_data = $db->fetch_row(
                    "SELECT m.valeur AS valeur, n.renewal_period AS renewal_period 
                    FROM ".$pre."misc AS m, 
                    ".$pre."nested_tree AS n 
                    WHERE m.type='complex' 
                    AND m.intitule = n.id 
                    AND m.intitule = ".$t->id 
                );
                
                
                echo '<tr class="ligne'.($x%2).'">
                        <td align="center">'.$t->id.'</td>
                        <td width="50%">
                            '.$ident.'<span class="editable_textarea" style="" id="title_'.$t->id.'">'.$t->title.'</span>
                        </td>
                        <td align="center">
                            <span class="editable_select" id="complexite_'.$t->id.'">'.$mdp_complexite[$node_data[0]][1].'</span>
                        </td>               
                        <td align="center">
                            <span class="editable_select" id="parent_'.$t->id.'">'.$data[0].'</span>
                        </td>
                        <td align="center">
                            '.$t->nlevel.'
                        </td>
                        <td align="center">
                            <span class="renewal_textarea" id="renewal_'.$t->id.'">'.$node_data[1].'</span>
                        </td>
                        <td align="center">
                            <img src="includes/images/folder--minus.png" onclick="supprimer_groupe(\''.$t->id.'\')" style="cursor:pointer;" />
                        </td>';
                        
                        $data3 = $db->fetch_row("SELECT bloquer_creation,bloquer_modification FROM ".$pre."nested_tree WHERE id = ".$t->id);
                        echo '
                        <td align="center">
                            <input type="checkbox" id="cb_droit_'.$t->id.'" onchange="Changer_Droit_Complexite(\''.$t->id.'\',\'creation\')"', isset($data3[0]) && $data3[0]==1 ? 'checked' : '', ' />
                        </td>
                        <td align="center">
                            <input type="checkbox" id="cb_droit_modif_'.$t->id.'" onchange="Changer_Droit_Complexite(\''.$t->id.'\',\'modification\')"', isset($data3[1]) && $data3[1]==1 ? 'checked' : '', ' />
                        </td>
                </tr>';
                array_push($arr_ids,$t->id);
                $x++;
            }
        }
        echo '
        </tbody>
    </table>
    <div style="font-size:11px;font-style:italic;margin-top:5px;">
        <img src="includes/images/information-white.png" alt="" />&nbsp;'.$txt['info_click_to_edit'].'
    </div>
    </div>
</form>';

//Launch Editable script on DOM elements
foreach($arr_ids as $id)
    echo '   
    <script type="text/javascript">
        $("#complexite_'.$id.'").editable("sources/groups.queries.php", { 
            indicator : "<img src=\'includes/images/loading.gif\' />",
            data   : "{'.$liste_complexite.', \'selected\':\''.$mdp_complexite[$node_data[0]][1].'\'}",
            type   : "select",
            submit : "<img src=\'includes/images/disk_black.png\' />",
            cancel : " <img src=\'includes/images/cross.png\' />",
            name : "changer_complexite"
          });
          $("#parent_'.$id.'").editable("sources/groups.queries.php", { 
            indicator : "<img src=\'includes/images/loading.gif\' />",
            data   : "{'.$liste_groupes.', \'selected\':\''.$data[0].'\'}",
            type   : "select",
            submit : "<img src=\'includes/images/disk_black.png\' />",
            cancel : " <img src=\'includes/images/cross.png\' />",
            name : "newparent_id"
          });
    </script>';

//Formulaire Ajouter GROUPE
echo '
<div id="div_add_group" style="display:none;"> 
    <div id="addgroup_show_error" style="text-align:center;margin:2px;display:none;" class="ui-state-error ui-corner-all"></div>
    <label for="ajouter_groupe_titre" class="form_label_120">'.$txt['group_title'].'</label>
    <input type="text" size="30" id="ajouter_groupe_titre" />
    <br />
    
    <label for="parent_id" class="form_label_120">'.$txt['group_parent'].'</label>
    <select id="parent_id">';
        echo '<option value="na">---'.$txt['select'].'---</option>';
        echo '<option value="0">'.$txt['root'].'</option>';
        $prev_level = 0;
        foreach($tst as $t){
            if ( in_array($t->id,$_SESSION['groupes_visibles']) ) {
                $ident="";
                for($x=1;$x<$t->nlevel;$x++) $ident .= "&nbsp;&nbsp;";
                if ( $prev_level < $t->nlevel ){
                    echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
                }else if ( $prev_level == $t->nlevel ){
                   echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
                }else{
                    echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
                }
                $prev_level = $t->nlevel;
            }
        }
    echo '
    </select>
    <br />
    
    <label for="new_rep_complexite" class="form_label_120">'.$txt['complex_asked'].'</label>
    <select id="new_rep_complexite">
        <option value="">---</option>';
        foreach($mdp_complexite as $complex)
            echo '<option value="'.$complex[0].'">'.$complex[1].'</option>';
    echo '
    </select>
    <br />
    
    <label for="add_node_renewal_period" class="form_label_120">'.$txt['group_pw_duration'].'</label>
    <input type="text" size="30" id="add_node_renewal_period" value="0" />
</div>';
?>
<script type="text/javascript">
$(function() {
    //inline editing
    $(".editable_textarea").editable("sources/groups.queries.php", { 
          indicator : "<img src='includes/images/loading.gif' />",
          type   : "textarea",
          select : true,
          submit : " <img src='includes/images/disk_black.png' />",
          cancel : " <img src='includes/images/cross.png' />",
          name : "newtitle",
          width : "240"
      });
      
      //inline editing
    $(".renewal_textarea").editable("sources/groups.queries.php", { 
          indicator : "<img src='includes/images/loading.gif' />",
          type   : "textarea",
          select : true,
          submit : " <img src='includes/images/disk_black.png' />",
          cancel : " <img src='includes/images/cross.png' />",
          name : "renewal_period",
          width : "40"
      });
      
      //Prepare creation dialogbox
      $('#open_add_group_div').click(function() {
            $('#div_add_group').dialog('open');
      });

      $("#div_add_group").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        width: 350,
        height: 220,
        title: "<?php echo $txt['add_new_group'];?>",
        buttons: {
            "<?php echo $txt['save_button'];?>": function() {
                ajouter_groupe();
            },
            "<?php echo $txt['cancel_button'];?>": function() {
                $(this).dialog('close');
            }
        }
    });
});



function ajouter_groupe(){
    //Check if renewal_period is an integer
    if ( isInteger(document.getElementById("add_node_renewal_period").value) == false ){
        document.getElementById("addgroup_show_error").innerHTML = "<?php echo $txt['error_renawal_period_not_integer'];?>";
        $("#addgroup_show_error").show();
    }else{
        if ( document.getElementById("new_rep_complexite").value == "" ){
            document.getElementById("addgroup_show_error").innerHTML = "<?php echo $txt['error_group_complex'];?>";
            $("#addgroup_show_error").show();
        }else{
            if ( document.getElementById('ajouter_groupe_titre').value != "" && document.getElementById('parent_id').value != "na" ){
                $("#addgroup_show_error").hide();
                var data = "type=ajouter_groupe"+
                            "&titre="+escape(document.getElementById('ajouter_groupe_titre').value)+
                            "&complex="+document.getElementById('new_rep_complexite').value+
                            "&renewal_period="+document.getElementById('add_node_renewal_period').value+
                            "&parent_id="+document.getElementById('parent_id').value;
                httpRequest("sources/groups.queries.php",data);
                $("#div_add_group").dialog('close');
            }else{
                document.getElementById("addgroup_show_error").innerHTML = "<?php echo $txt['error_fields_2'];?>";
                $("#addgroup_show_error").show();
            }
        }
    }
}

function supprimer_groupe(id){
    if ( confirm("<?php echo $txt['confirm_delete_group'];?>") ){
        var data = "type=supprimer_groupe&id="+id;
        httpRequest("sources/groups.queries.php",data);
    }
}   

function Changer_Droit_Complexite(id,type){
    var droit = 0;
    if ( type == "creation" ){
        if ( document.getElementById('cb_droit_'+id).checked == true ) droit = 1;
        var data = "type=modif_droit_autorisation_sans_complexite&id="+id+"&droit="+droit;
    }else if ( type == "modification" ){
        if ( document.getElementById('cb_droit_modif_'+id).checked == true ) droit = 1;
        var data = "type=modif_droit_modification_sans_complexite&id="+id+"&droit="+droit;
    }
    httpRequest("sources/groups.queries.php",data);   
}
</script>
Return current item: cPassMan