Example #1
0
{
    /**
     * A simple property that define if the admin content is showed in admin view or raw (you can use headers if you want in your admin code).
     */
    public static $show_admin_view = true;
    /**
     * A property that define the index of admin
     * 
     */
    public static $admin_controller = array('admin', 'vendor/phangoapp/admin/controllers/admin/admin_admin');
    /**
     * The name of the default admin home.You need change it if you changed the admin controller 
     * 
     */
    public static $name_admin = '';
    /**
     * A simple method for create urls for use in admin
     *
     * With this method you can create easily urls for your admin site
     *
     * @param string $text_admin The module to admin
     * @param array $parameters An array with format key value used for set get values in the new url
     */
    public static function set_admin_link($text_admin, $parameters = array())
    {
        #return Routes::make_module_url(ADMIN_FOLDER, 'index', 'home', array($text_admin), $get=$parameters);
        return Routes::make_simple_url(ADMIN_FOLDER, array($text_admin), $parameters);
    }
}
AdminUtils::$name_admin = I18n::lang('phangoapp/admin', 'admin', 'Admin');
Example #2
0
 public function home($module_id = 'none', $submodule_id = '')
 {
     if ($submodule_id != '') {
         $module_id = basename(Utils::slugify($module_id)) . '/' . basename(Utils::slugify($submodule_id));
     }
     class_alias('indexController', 'AdminSwitchClass');
     AdminSwitchClass::$login = new LoginClass(Webmodel::$model['user_admin'], 'user_admin', 'password', '', $arr_user_session = array('IdUser_admin', 'privileges_user', 'username', 'token_client', 'lang'), $arr_user_insert = array('user_admin', 'password', 'repeat_password', 'email'));
     AdminSwitchClass::$login->field_key = 'token_client';
     ob_start();
     //global $model, $lang, PhangoVar::$base_url, PhangoVar::$base_path, $user_data, $arr_module_admin, $config_data, $arr_block, $original_theme, $module_admin, $header;
     $header = '';
     $content = '';
     //load_libraries(array('utilities/set_admin_link'));
     //settype($module_id, 'string');
     $module_id = Utils::slugify($module_id, 1);
     $extra_urls = array();
     //Make menu...
     //Admin was internationalized
     if (AdminSwitchClass::$login->check_login()) {
         LoginClass::$session['user_admin']['token_client'] = sha1(LoginClass::$session['user_admin']['token_client']);
         if (!isset($_SESSION['language'])) {
             $_SESSION['language'] = LoginClass::$session['user_admin']['lang'];
         }
         I18n::load_lang('phangoapp/admin');
         Utils::load_config('config_admin', 'settings/admin');
         //variables for define titles for admin page
         $arr_son_module = array();
         $title_admin = I18n::lang('phangoapp/admin', 'admin', 'Admin');
         $title_module = I18n::lang('phangoapp/admin', 'home', 'Home');
         $content = '';
         $name_modules = array();
         $no_show_menu = [];
         $urls = array();
         $arr_permissions_admin = array();
         $arr_permissions_admin['none'] = 1;
         $module_admin = array();
         $arr_admin_script['none'] = AdminUtils::$admin_controller;
         //Define $module_admin[$module_id] for check if exists in database the module
         $module_admin[$module_id] = 'AdminIndex';
         //I18n::$lang[$module_admin[$module_id].'_admin']['AdminIndex_admin_name']=ucfirst(I18n::lang('phangoapp/admin', 'admin', 'Admin'));
         //0=> name in uri, 1 => route to script, 2 name of script
         $title_admin = AdminUtils::$name_admin;
         foreach (ModuleAdmin::$arr_modules_admin as $ser_admin_script) {
             //load little file lang with the name for admin. With this you don't need bloated with biggest files of langs...
             $idmodule = $ser_admin_script[0];
             $name_module = $idmodule;
             if (gettype($ser_admin_script[1]) == 'string') {
                 $name_modules[$name_module] = $ser_admin_script[2];
                 $arr_admin_script[$idmodule] = $ser_admin_script;
                 $urls[$name_module] = AdminUtils::set_admin_link($idmodule, array());
                 $module_admin[$idmodule] = $name_module;
                 $arr_permissions_admin[$idmodule] = 1;
                 if (isset($ser_admin_script[3])) {
                     $no_show_menu[$name_module] = 1;
                 }
             } else {
                 $name_modules[$name_module] = $ser_admin_script[2];
                 //unset(ModuleAdmin::$arr_modules_admin[$idmodule]['title']);
                 foreach ($ser_admin_script[1] as $ser_admin_script_son) {
                     $idmodule_son = $ser_admin_script_son[0];
                     $name_module_son = $idmodule_son;
                     $name_modules[$name_module_son] = $ser_admin_script_son[2];
                     $arr_admin_script[$idmodule_son] = $ser_admin_script_son;
                     $urls[$name_module_son] = AdminUtils::set_admin_link($idmodule_son, array());
                     $module_admin[$idmodule_son] = $name_module_son;
                     $arr_permissions_admin[$idmodule_son] = 1;
                     if (isset($ser_admin_script_son[3])) {
                         $no_show_menu[$name_module_son] = 1;
                     }
                 }
             }
         }
         if (!isset($arr_admin_script[$module_id])) {
             //Need show error.
             $this->route->response404();
             die;
         }
         //$file_include=Routes::$base_path.'/vendor/'.$arr_admin_script[ $module_id ][1].'/controllers/admin/admin_'.basename($arr_admin_script[ $module_id ][0]).'.php';
         $file_include = Routes::$base_path . '/' . $arr_admin_script[$module_id][1] . '.php';
         if (LoginClass::$session['user_admin']['privileges_user'] == 1) {
             $arr_permissions_admin = array();
             $arr_module_saved = array();
             $arr_module_strip = array();
             $arr_permissions_admin[$module_id] = 0;
             $arr_permissions_admin['none'] = 1;
             Webmodel::$model['moderators_module']->set_conditions(['where moderator=?', [$_SESSION['IdUser_admin']]]);
             $query = Webmodel::$model['moderators_module']->select(array('idmodule'), 1);
             while (list($idmodule_mod) = Webmodel::$model['moderators_module']->fetch_row($query)) {
                 //settype($idmodule_mod, 'integer');
                 $arr_permissions_admin[$idmodule_mod] = 1;
                 $arr_module_saved[] = $module_admin[$idmodule_mod];
             }
             $arr_module_strip = array_diff(array_keys($name_modules), $arr_module_saved);
             foreach ($arr_module_strip as $name_module_strip) {
                 unset($name_modules[$name_module_strip]);
                 unset($urls[$name_module_strip]);
             }
         }
         if (file_exists($file_include) && $module_admin[$module_id] != '' && $arr_permissions_admin[$module_id] == 1) {
             include $file_include;
             $func_admin = basename($module_admin[$module_id]) . 'Admin';
             if ($module_id != 'none') {
                 $title_admin = $name_modules[$module_id];
             }
             if (function_exists($func_admin)) {
                 $extra_data = $func_admin();
                 settype($extra_data, 'array');
                 $extra_data = array_merge($extra_data, $arr_son_module);
             } else {
                 throw new Exception('Error: no exists function ' . ucfirst($func_admin) . ' for admin application');
             }
         } else {
             if ($module_admin[$module_id] != '' && $arr_permissions_admin[$module_id] == 1) {
                 $output = ob_get_contents();
                 ob_clean();
                 throw new Exception('Error: no exists file ' . $file_include . ' for admin application');
                 die;
             } else {
                 $this->route->response404();
                 die;
             }
         }
         $content = ob_get_contents();
         ob_end_clean();
         if (AdminUtils::$show_admin_view == true) {
             $content = '<h1>' . $title_admin . "</h1>\n" . $content;
             echo View::load_view(array('header' => $header, 'title' => I18n::lang('phangoapp/admin', 'admin_zone', 'Admin zone'), 'content' => $content, 'name_modules' => $name_modules, 'urls' => $urls, 'extra_data' => $extra_data, 'no_show_menu' => $no_show_menu), 'admin/admin');
         } else {
             echo $content;
         }
     } else {
         $url = Routes::make_simple_url(ADMIN_FOLDER . '/login');
         die(header('Location: ' . $url, true));
     }
 }
Example #3
0
function UserOptionsListModel($url_options, $model_name, $id, $arr_row)
{
    $arr_options = SimpleList::BasicOptionsListModel($url_options, $model_name, $id, $arr_row);
    if ($arr_row['privileges_user'] == 1) {
        $arr_options[] = '<a href="' . AdminUtils::set_admin_link('ausers', array('op' => 1, 'IdUser_admin' => $id)) . '">' . I18n::lang('phangoapp/admin', 'change_user_modules', 'Change user modules') . '</a>';
    }
    return $arr_options;
}
Example #4
0
function AdminView($header, $title, $content, $name_modules, $url_modules, $extra_data, $no_show_menu)
{
    View::$js[] = 'jquery.min.js';
    View::$css[] = 'font-awesome.min.css';
    View::$js_module['admin'][] = 'responsive-nav.min.js';
    View::$css_module['admin'][] = 'admin.css';
    View::$css_module['admin'][] = 'responsive-nav.css';
    ?>
    <!DOCTYPE html>
    <html>
    <head>                                                                                          
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
    <title><?php 
    echo $title;
    ?>
</title>
    <?php 
    echo View::load_css();
    ?>
    <?php 
    echo View::load_js();
    ?>
    <?php 
    echo View::load_header();
    ?>
 
    </head>
    <body>
    <div id="logout">
    <a href="<?php 
    echo AdminUtils::set_admin_link('login/logout');
    ?>
"><i class="fa fa-power-off" aria-hidden="true"></i> Logout</a>
    </div>

    <div id="center_body">
        <div id="header">
            <a href="#nav" id="toggle"><i class="fa fa-bars" aria-hidden="true"></i><span>Menu</span></a>
            <span id="title_phango">Phango</span> <span id="title_framework">Framework!</span> 
            <div id="languages_general">
            <?php 
    $arr_selected = array();
    foreach (I18n::$arr_i18n as $lang_item) {
        //set
        $arr_selected[Utils::slugify($lang_item)] = 'no_choose_flag_general';
        $arr_selected[Utils::slugify(I18n::$language)] = 'choose_flag_general';
        ?>
                <a class="<?php 
        echo $arr_selected[Utils::slugify($lang_item)];
        ?>
" href="<?php 
        echo Routes::make_module_url('lang', 'index', 'home', array('language' => $lang_item));
        ?>
"><img src="<?php 
        echo View::get_media_url('images/languages/' . $lang_item . '.png');
        ?>
" alt="<?php 
        echo $lang_item;
        ?>
"/></a> 
                <?php 
    }
    ?>
            </div>
        </div>
        <div class="content_admin">
            <nav id="menu" class="nav-collapse">
                <ul>
                    <li class="menu_title"><i class="fa fa-gear" aria-hidden="true"></i> <?php 
    echo I18n::lang('phangoapp/admin', 'applications', 'Applications');
    ?>
</li>
                    <?php 
    foreach ($name_modules as $key_module => $name_module) {
        if (!isset($no_show_menu[$key_module])) {
            if (isset($url_modules[$key_module])) {
                ?>
                            <li><a href="<?php 
                echo $url_modules[$key_module];
                ?>
"><i class="fa fa-circle-o" aria-hidden="true"></i> <?php 
                echo $name_module;
                ?>
</a></li>
                            <?php 
            } else {
                echo '<li><div class="father_admin">' . $name_module . '</div></li>';
            }
        }
        //If have $key_module with an extra_url element from extra_data, put here.
        if (isset($extra_data['extra_url'][$key_module])) {
            foreach ($extra_data['extra_url'][$key_module]['url_module'] as $key => $url_module) {
                ?>
								<li><a class="sub_module" href="<?php 
                echo $url_module;
                ?>
">&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-circle-o" aria-hidden="true"></i> <?php 
                echo ucfirst($extra_data['extra_url'][$key_module]['name_module'][$key]);
                ?>
</a></li>
								<?php 
            }
        }
    }
    ?>
                </ul>
            </nav>
            <div class="contents">
                    <?php 
    echo View::show_flash();
    ?>
					<?php 
    echo $content;
    ?>
            </nav>
        </div>
    </div>
    <div id="loading_ajax">
    </div>
    <script>
        var navigation = responsiveNav(".nav-collapse", {customToggle: "#toggle"});
    </script>
    </body>
    </html>

    <?php 
}