Location: PHPKode > projects > cPassMan > cpassman_1.55/functions.php
<?php
####################################################################################################
## File : functions.php
## Author : Nils Laumaillé
## Description : Function page
## 
## DON'T CHANGE !!!
## 
####################################################################################################
?>
<script src="includes/js/jquery.jeditable.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
    $("#change_group_autgroups").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        width: 400,
        height: 400,
        title: "<?php echo $txt['change_user_autgroups_title'];?>",
        buttons: {
            "<?php echo $txt['save_button'];?>": function() {
                LoadingPage();  //show loading div
                Change_groups(document.getElementById("selected_function").value,"autgroups");
                $(this).dialog('close');
                LoadingPage();  //hide loading div
            },
            "<?php echo $txt['cancel_button'];?>": function() {
                $(this).dialog('close');
            }
        }
    });
    
    $("#change_group_forgroups").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        width: 400,
        height: 400,
        title: "<?php echo $txt['change_user_forgroups_title'];?>",
        buttons: {
            "<?php echo $txt['save_button'];?>": function() {
                LoadingPage();  //show loading div
                Change_groups(document.getElementById("selected_function").value,"forgroups");
                $(this).dialog('close');
                LoadingPage();  //hide loading div
            },
            "<?php echo $txt['cancel_button'];?>": function() {
                $(this).dialog('close');
            }
        }
    });
    
    $("#add_new_function").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        width: 400,
        height: 150,
        title: "<?php echo $txt['give_function_title'];?>",
        buttons: {
            "<?php echo $txt['save_button'];?>": function() {
                LoadingPage();  //show loading div
                var data = "type=add_new_function&"+
                    "&name="+document.getElementById("new_function").value;
                httpRequest("sources/functions.queries.php",data);
                $(this).dialog('close');
            },
            "<?php echo $txt['cancel_button'];?>": function() {
                $(this).dialog('close');
            }
        }
    });
    
    $("#delete_role").dialog({
        bgiframe: true,
        modal: true,
        autoOpen: false,
        width: 400,
        height: 150,
        title: "<?php echo $txt['admin_action'];?>",
        buttons: {
            "<?php echo $txt['ok'];?>": function() {
                LoadingPage();  //show loading div
                var data = "type=delete_role&id="+document.getElementById("delete_role_id").value;
                httpRequest("sources/functions.queries.php",data);
                $(this).dialog('close');
            },
            "<?php echo $txt['cancel_button'];?>": function() {
                $(this).dialog('close');
            }
        }
    });
    
    refresh_matrice();
});
</script>
<?php
//Get full list of groups
$arr_groups = array();
$rows = $db->fetch_all_array("SELECT id,title FROM ".$pre."nested_tree");
foreach( $rows as $reccord )
    $arr_groups[$reccord['id']] = $reccord['title'];

//display     
echo '
<div class="title ui-widget-content ui-corner-all">'.$txt['admin_functions'].'&nbsp;&nbsp;&nbsp;<img src="includes/images/users--plus.png" title="'.$txt['add_role_tip'].'" onclick="OpenDialog(\'add_new_function\')" style="cursor:pointer;" /></div>
<form name="form_fonctions" method="post" action="">
    <div style="line-height:20px;" align="center">
        <table cellspacing="0" cellpadding="5" width="80%">
            <thead>
                <tr>
                    <th min-width="5%">ID</th>
                    <th min-width="20%">'.$txt['label'].'</th>
                    <th min-width="35%">'.$txt['assoc_authorized_groups'].'</th>
                    <th min-width="35%">'.$txt['assoc_forbidden_groups'].'</th>
                    <th min-width="5%" title="'.$txt['del_function'].'"><img src="includes/images/users--minus.png" /></th>
                </tr>
            </thead>
            <tbody>';
        $x = 0;
        $rows = $db->fetch_all_array("SELECT * FROM ".$pre."functions");
        foreach( $rows as $reccord ){
            //Get list of allowed groups
                $list_allo_grps = "";
                $list = explode(';',$reccord['groupes_visibles']);
                foreach($list as $elem){
                    if ( !empty($elem) ) $list_allo_grps .= '<img src="includes/images/arrow-000-small.png" />'.$arr_groups[$elem]."<br />";
                }
                if ( empty($list_allo_grps) ) $list_allo_grps = '<img src="includes/images/error.png" title="'.$txt['function_alarm_no_group'].'" />';
            
            //Get list of forbiden groups
                $list_forb_grps = "";
                $list = explode(';',$reccord['groupes_interdits']);
                foreach($list as $elem){
                    if ( !empty($elem) ) $list_forb_grps .= '<img src="includes/images/arrow-000-small.png" />'.$arr_groups[$elem]."<br />";
                }
                
            //Display Grid
            echo '
                <tr class="ligne'.($x%2).'">
                    <td align="center">'.$reccord['id'].'</td>
                    <td align="center"><p class="editable_textarea" id="title_'.$reccord['id'].'">'.str_replace('&','&amp;',$reccord['title']).'</p></td>
                    <td>
                        <div id="list_autgroups_function_'.$reccord['id'].'" style="text-align:center;">'
                        .$list_allo_grps.'
                        </div>
                        <div style="text-align:center;"><img src="includes/images/cog_edit.png" style="cursor:pointer;" onclick="Open_Div_Change(\''.$reccord['id'].'\',\'autgroups\')" title="'.$txt['change_authorized_groups'].'" /></div>
                    </td>
                    <td>
                        <div id="list_forgroups_function_'.$reccord['id'].'" style="text-align:center;">'
                        .$list_forb_grps.'
                        </div>
                        <div style="text-align:center;"><img src="includes/images/cog_edit.png" style="cursor:pointer;" onclick="Open_Div_Change(\''.$reccord['id'].'\',\'forgroups\')" title="'.$txt['change_forbidden_groups'].'" /></div>
                    </td>
                    <td align="center">
                        <img src="includes/images/users--minus.png" onclick="delete_this_role(\''.$reccord['id'].'\',\''.str_replace('&','&amp;',$reccord['title']).'\')" style="cursor:pointer;" />
                    </td>
                </tr>';
                $x++;
            }
            echo '
            </tbody>
        </table>
    </div>';
    
    //Traceability Matrix
    echo '        
    <div class="title ui-widget-content ui-corner-all" style="margin-top:25px;">'.$txt['rights_matrix'].'
        <a onClick="refresh_matrice()"><img src="includes/images/arrow_refresh.png" style="cursor:pointer" /></a>
        &nbsp;<img id="ajax_loader_matrix" style="display:none;" src="includes/images/ajax-loader.gif" alt="" />
    </div>
    <div style="line-height:20px;" align="center">
        <div id="matrice_droits"></div>
    </div>
</form>
<input type="hidden" id="selected_function" />';

// DIV FOR CHANGING AUTHORIZED GROUPS
echo '
<div id="change_group_autgroups">'.
$txt['change_group_autgroups_info'].'
<form name="tmp_autgroups" action="">
<div id="change_group_autgroups_list" style="margin-left:15px;"></div>
</form>
</div>';

// DIV FOR CHANGING ROLES
echo '
<div id="change_group_forgroups">'.
$txt['change_group_forgroups_info'].'
<form name="tmp_forgroups" action="">
<div id="change_group_forgroups_list" style="margin-left:15px;"></div>
</form>
</div>';

// DIV FOR ADDING A ROLE
echo '
<div id="add_new_function" style="">
    <label for="new_function" class="form_label_100">'.$txt['name'].'</label><input type="text" id="new_function" size="40" />
</div>';

// DIV FOR DELETING A ROLE
echo '
<div id="delete_role" style="display:none;">
    <div>'.$txt['confirm_del_role'].'</div>
    <div style="font-weight:bold;text-align:center;color:#FF8000;text-align:center;font-size:13pt;" id="delete_role_show"></div>
    <input type="hidden" id="delete_role_id" />
</div>';

?>
<script type="text/javascript">
$(function() {     
    //inline editing
    $(".editable_textarea").editable("sources/functions.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 : "edit_fonction"

      });
});

function Open_Div_Change(id,type){ 
    $("#div_loading").show();
    var data = "type=open_div_"+type+"&id="+id;
    httpRequest("sources/functions.queries.php",data);  
}

function Change_groups(id,type){
    var list = "";
    if ( type == "autgroups" ) var form = document.forms.tmp_autgroups;
    if ( type == "forgroups" ) var form = document.forms.tmp_forgroups;
    
    for (i=0 ; i<= form.length-1 ; i++){
        if (form[i].type == 'checkbox' && form[i].checked){
            function_id = form[i].id.split('-')
            if ( list == "" ) list = function_id[1];
            else list = list + ";" + function_id[1];
        }
    }
    if ( type == "autgroups" ) var data = "type=change_function_autgroups&id="+id+"&list="+list;
    if ( type == "forgroups" ) var data = "type=change_function_forgroups&id="+id+"&list="+list;
    httpRequest("sources/functions.queries.php",data);  
}

function delete_this_role(id,name){
    document.getElementById("delete_role_id").value = id;
    document.getElementById("delete_role_show").innerHTML = name;
    $('#delete_role').dialog("open");
}  

function refresh_matrice(){
    var data = "type=rafraichir_matrice";
        httpRequest("sources/functions.queries.php",data);
}
</script>
Return current item: cPassMan