Skip to content
Snippets Groups Projects
add_users_entities.php 4.85 KiB
Newer Older
  • Learn to ignore specific revisions
  • SNA's avatar
    SNA committed
    <?php
    /**
    * File : add_users_entities.php
    *
    
    * Form to add an entity to a user, pop up page
    
    SNA's avatar
    SNA committed
    *
    * @package  Maarch Framework 3.0
    * @version 1
    * @since 03/2009
    * @license GPL
    
    Odran PHILIBERT's avatar
    Odran PHILIBERT committed
    * @author  C�dric Ndoumba  <dev@maarch.org>
    
    SNA's avatar
    SNA committed
    */
    
    SNA's avatar
    SNA committed
    try{
    
    SNA's avatar
    SNA committed
        require_once("modules/entities/class/EntityControler.php");
    
    SNA's avatar
    SNA committed
    } catch (Exception $e){
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        functions::xecho($e->getMessage());
    
    SNA's avatar
    SNA committed
    }
    core_tools::load_lang();
    
    //core_tools::test_admin('manage_entities', 'entities');
    
    SNA's avatar
    SNA committed
    
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    require_once('modules/entities/class/class_manage_entities.php');;
    
    SNA's avatar
    SNA committed
    $ent = new entity();
    
    SNA's avatar
    SNA committed
    $entity_ctrl = new EntityControler();
    
    SNA's avatar
    SNA committed
    //$except = array();
    
    SNA's avatar
    SNA committed
    /* If you want that a user can not belong to an entity and one of this entity subentity, decomment these lines
    for($i = 0; $i < count($_SESSION['m_admin']['entity']['entities']); $i++)
    {
    
    SNA's avatar
    SNA committed
        $except[] = $_SESSION['m_admin']['entity']['entities'][$i]['ENTITY_ID'];
    
    SNA's avatar
    SNA committed
    }
    */
    
    
    $entities = array();
    
    Odran PHILIBERT's avatar
    Odran PHILIBERT committed
    //$entities = $entity_ctrl->getAllEntities(); // To do : recup l'arborescence des entit�s
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    $entities = $entity_ctrl->getAllEntities();
    //var_dump($entities);
    $EntitiesIdExclusion = array();
    if ($_SESSION['user']['UserId'] != 'superadmin') {
        $my_tab_entities_id = $ent->get_all_entities_id_user($_SESSION['user']['entities']);
        $my_tab_entities_id = array_unique($my_tab_entities_id);
        //var_dump($my_tab_entities_id);
        if (count($my_tab_entities_id) > 0) {
            $countEntities = count($entities);
            for ($cptAllEnt = 0;$cptAllEnt<$countEntities;$cptAllEnt++) {
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                //$result = array_search("'" . $entities[$cptAllEnt]->__get('entity_id') . "'", $my_tab_entities_id);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                //var_dump($result);
                if (!is_integer(array_search("'" . $entities[$cptAllEnt]->__get('entity_id') . "'", $my_tab_entities_id))) {
                    array_push($EntitiesIdExclusion, $entities[$cptAllEnt]->__get('entity_id'));
                    unset($entities[$cptAllEnt]);
                }
            }
        }
    } else {
        $entities = $entity_ctrl->getAllEntities();
    }
    $entities = array_values($entities);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    $allEntitiesTree= array();
    $allEntitiesTree = $ent->getShortEntityTreeAdvanced(
        $allEntitiesTree, 'all', '', $EntitiesIdExclusion, 'all'
    );
    //var_dump($allEntitiesTree);
    
    
    SNA's avatar
    SNA committed
    function in_session_array($entity_id)
    {
    
    SNA's avatar
    SNA committed
        for($i=0; $i<count($_SESSION['m_admin']['entity']['entities']);$i++)
        {
            if(trim($entity_id) == trim($_SESSION['m_admin']['entity']['entities'][$i]['ENTITY_ID']))
                return true;
        }
        return false;
    
    SNA's avatar
    SNA committed
    }
    
    SNA's avatar
    SNA committed
    ?>
    <div class="popup_content">
    
    <h2 class="tit"><?php echo USER_ADD_ENTITY;?></h2>
    
    <form name="chooseEntity" id="chooseEntity" method="get" action="#" class="forms" style="height:350px;">
    
    SNA's avatar
    SNA committed
    <p>
    
        <label for="entity_id" style="width:90%;"> <?php echo _CHOOSE_ENTITY;?> : </label>
    
        <select name="entity_id" id="entity_id" size="30" style="width: auto" >
    
    SNA's avatar
    SNA committed
        <?php
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    		
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            $countAllEntities = count($allEntitiesTree);
            for ($cptEntities = 0;$cptEntities < $countAllEntities;$cptEntities++) {
                if (!$allEntitiesTree[$cptEntities]['KEYWORD']) {
    
                    $optionStr .= '<option title="' 
                        .  str_replace('&emsp;', '', $ent->show_string($allEntitiesTree[$cptEntities]['SHORT_LABEL'])) 
                        . '" data-object_type="entity_id" value="' 
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                        . $allEntitiesTree[$cptEntities]['ID'] . '"';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                    if ($allEntitiesTree[$cptEntities]['DISABLED']) {
                        $optionStr .= ' disabled="disabled" class="disabled_entity"';
                    } else {
                         //$optionStr .= ' style="font-weight:bold;"';
                    }
                    $optionStr .=  '>' 
                        .  $ent->show_string($allEntitiesTree[$cptEntities]['SHORT_LABEL']) 
                        . '</option>';
                }
            }
            echo $optionStr;
    
    SNA's avatar
    SNA committed
        ?>
        </select>
    
    Odran PHILIBERT's avatar
    Odran PHILIBERT committed
        <script type="text/javascript">$j("#entity_id").chosen({width: "95%", disable_search_threshold: 10, search_contains: true});</script>
    
    SNA's avatar
    SNA committed
    </p>
    <br/>
    <p>
    
        <label for="role"><?php echo _ROLE;?> : </label>
    
        <input type="text"  name="role" id="role" style="width:90%;" />
    
    SNA's avatar
    SNA committed
    </p>
    <br/>
    
    <p class="buttons" style="position:absolute;bottom:5px;margin:0px;padding:0px;left:0px;text-align:center;width:100%;">
    
        <input type="button" name="Submit" value="<?php echo _VALIDATE;?>" class="button" onclick="checkUserEntity('chooseEntity', '<?php echo $_SESSION['config']['businessappurl'].'index.php?display=true&module=entities&page=check_user_entities';?>', '<?php echo $_SESSION['config']['businessappurl'].'index.php?display=true&module=entities&page=manage_user_entities';?>', '<?php echo $_SESSION['config']['businessappurl'].'index.php?display=true&module=entities&page=users_entities_form';?>');"  />
        <input type="button" name="cancel" value="<?php echo _CANCEL;?>" class="button"  onclick="destroyModal('add_user_entities');"/>
    
    SNA's avatar
    SNA committed
    </p>
    
    </form>
    </div>