Skip to content
Snippets Groups Projects
Select Git revision
  • c17bf98a65e65f499dadd3427690f2dad2cba0f3
  • master default protected
  • Legacy_Php7
3 results

bootstrap.bundle.min.js

Blame
  • inc_functions.php 11.83 KiB
    <?php
    
    /* ######################################################################
    
      IML DEPLOYMENT
    
      included functions for the act_*.php files
    
      ---------------------------------------------------------------------
      2013-11-08  Axel <axel.hahn@iml.unibe.ch>
      ###################################################################### */
    
    
    if (!isset($aConfig) || !is_array($aConfig)){
        die("FATAL ERROR: \$aConfig does not exist. The config was not included before including ".__FILE__." in the request/ script.\n");
    }
    
    global $aParams;
    $aParams = array();
    
    
    
    // remark: $_SERVER does not exist in CLI
    if (isset($_SERVER) && is_array($_SERVER) && array_key_exists("REQUEST_URI", $_SERVER)){
        /*
          print_r($_GET);
          print_r($_POST);
          print_r($aParams);
          print_r($_SERVER);
          echo $_SERVER["REQUEST_URI"];
         */
        $aTmp = preg_split("#/#", $_SERVER["REQUEST_URI"]);
        if (count($aTmp) > 1 && $aTmp[1] == "deployment" && $aTmp[2] != "?") {
            array_shift($aTmp);
            array_shift($aTmp);
            if ($aTmp[count($aTmp) - 1] == "?") {
                array_pop($aTmp);
            }
            if ($aTmp[0])
                $aParams["prj"] = $aTmp[0];
            if (count($aTmp) > 1 && $aTmp[1])
                $aParams["action"] = $aTmp[1];
            if (count($aTmp) > 2 && $aTmp[2])
                $aParams["par3"] = $aTmp[2];
            if (count($aTmp) > 3 && $aTmp[3])
                $aParams["par4"] = $aTmp[3];
        }
        if (count($_GET))
            foreach ($_GET as $key => $value)
                $aParams[$key] = $value;
        if (count($_POST))
            foreach ($_POST as $key => $value)
                $aParams[$key] = $value;
    }
    
    $sImageBase = "/deployment/images/nuvola64x64/";
    $aImages = array(
        'overview' => 'apps/fsview.png',
        'project' => 'filesystems/desktop.png',
        'action' => 'apps/aktion.png',
        'build' => 'apps/kthememgr.png',
    );
    
    /**
     * get home link as button
     * @return string
     */
    function aHome($sClass = "btn") {
        global $aParams;
        // if (!array_key_exists("prj", $aParams)) return false;
        return '<a href="/deployment/?" class="' . $sClass . '"><i class="icon-home"></i> ' . t("menu-overview") . '</a>';
    }
    
    /**
     * get project Home link as button
     * @return string
     */
    function aPrjHome($sClass = "btn") {
        global $aParams, $aConfig;
        if (!array_key_exists("prj", $aParams))
            return false;
        if ($aParams["prj"] == "all")
            return aHome($sClass);
        // if (!array_key_exists("action", $aParams)) return false;
    
        require_once("./classes/project.class.php");
        $oPrj = new project($aParams["prj"]);
        return '<a href="/deployment/' . $aParams["prj"] . '/" class="' . $sClass . '"><i class="icon-book"></i> ' . t("menu-project-home") . ' <strong>' . $oPrj->getLabel() . '</strong></a>';
    }
    
    /**
     * auto generate upper part of the page with header and navigation 
     * @global type $aParams
     * @return type
     */
    function getTopArea() {
        global $aParams, $sImageBase, $aImages, $aConfig;
        $sReturn = '';
        require_once("./classes/project.class.php");
        require_once("./classes/projectlist.class.php");
    
        $oPrjList = new projectlist();
        $sMyPhase = "[phase]";
        $sMyRev = " [no rev] ";
        $sJsonfile = $_SERVER["DOCUMENT_ROOT"] . "ci-webgui.json";
        if (file_exists($sJsonfile)) {
            $aJson = json_decode(file_get_contents($sJsonfile), true);
            if (array_key_exists("date", $aJson))
                $sMyRev = $aJson["date"];
        }
        $sPhase = '(unknown)';
    
        // TODO - Phasen nach Hostname - das kann nicht public gehen
        $aPhases = array(
            'dev.ci.iml.unibe.ch' => array('phase' => 'dev',),
            'aum-cba02.unibe.ch' => array('phase' => 'preview',),
            'ci.iml.unibe.ch' => array('phase' => 'live',),
        );
        if (array_key_exists($_SERVER["SERVER_NAME"], $aPhases)) {
            $sPhase = $aPhases[$_SERVER["SERVER_NAME"]]["phase"];
        }
        $sBaseUrl = '/deployment/';
        $sWikiBaseUrl = 'https://secure.iml.unibe.ch/wiki/doku.php';
        $sReturn = '
            <div class="navbar">
              <span class="version ' . $sPhase . '">' . $sPhase . ' :: ' . $sMyRev . '</span>
              <div class="navbar-inner">
                <span class="brand">IML Deployment GUI</span>
                <ul class="nav">
                
                    <li class="dropdown';
                    if (!array_key_exists("prj", $aParams))$sReturn.=' active';
                    $sReturn.='">' . str_replace('</a>', ' <b class="caret"></b></a>', aHome("")) . '
                            <ul class="dropdown-menu">
                                <li><a href="' . $sBaseUrl . 'all/setup/">' . t("menu-settings") . '</a></li>
                                <li><a href="' . $sBaseUrl . 'all/setup/new/">' . t("menu-new-project") . '</a></li>
                            </ul>
                        </li>
    
                    <!-- list of projects -->
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">' . t("menu-projects") . '<b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            ';
        $oPrj1 = new project();
        foreach ($oPrj1->getProjects() as $sPrj) {
            $oPrj = new project($sPrj);
            $sReturn.='<li><a href="' . $sBaseUrl . $sPrj . '/">' . $oPrj->getLabel() . '</a></li>';
        }
        $sReturn.='
                        </ul>
                    </li>';
        if (array_key_exists("prj", $aParams) && $aParams["prj"] <> "all") {
            $oPrj = new project($aParams["prj"]);
            $sReturn.='
                        <li style="border-left: 1px solid #ccc;" class="active">' . aPrjHome(" ") . '</li>
                        ';
            if (array_key_exists("action", $aParams) and FALSE) {
                $sReturn.='<li><a href="#">Aktion: ' . $aParams["action"] . '</a></li>';
            } else {
                $sReturn.='
                            <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">' . t("menu-project-actions") . '<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="' . $sBaseUrl . $aParams["prj"] . '/build/">' . t("menu-project-build") . '</a></li>
                                <li><a href="' . $sBaseUrl . $aParams["prj"] . '/cleanup/">' . t("menu-project-cleanup") . '</a></li>
                                <li><a href="' . $sBaseUrl . $aParams["prj"] . '/setup/">' . t("menu-project-settings") . '</a></li>
                                <li><a href="' . $sBaseUrl . $aParams["prj"] . '/delete/">' . t("menu-project-delete") . '</a></li>
                            ';
                $sReturn.='</ul></li>';
    
                $aPhases = $oPrj->getActivePhases();
                if (count($aPhases)) {
                    $sReturn.='<li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">' . t("menu-project-phases") . '<b class="caret"></b></a>
                                    <ul class="dropdown-menu">';
                    foreach ($aPhases as $sPhase) {
                        $sReturn.='<li><a href="' . $sBaseUrl . $aParams["prj"] . '/phase/' . $sPhase . '/">' . $sPhase . '</a></li>';
                    }
                    $sReturn.='</ul></li>';
                }
            }
        }
    
        $sReturn.='
                    <!--
                    <li>
                        <a href="#" >Irgend...</a>
                    </li>
                    -->
                </ul>
                <ul class="nav pull-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class=" icon-question-sign"></i> ' . t("menu-help") . '<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="' . $sWikiBaseUrl . '/it/entwicklung/continuous_deployment">WIKI: Übersicht Continous Deployment</a></li>
                                <li><a href="' . $sWikiBaseUrl . '/it/entwicklung/continuous_deployment#konventionen">WIKI: Konventionen für Entwickler</a></li>
                                <li><a href="' . $sWikiBaseUrl . '/it/infrastruktur/dienste/puppet/snippets#iml-deployment">WIKI (Admin): Puppet-Snippets für den Sysadmin</a></li>
                                <li><a href="' . $sWikiBaseUrl . '/it/infrastruktur/dienste/imldeployment">WIKI (Admin): Verzeichnisse und Dateien</a></li>
                                <li><a href="/deployment/all/doc/">' . t("menu-help-classes") . '</a></li>
                            </ul>
                        </li>
                </ul>
              </div>          
            </div><div id="header2">';
    
        if (!array_key_exists("prj", $aParams)) {
            $sReturn.='<img src="' . $sImageBase . $aImages['overview'] . '" id="imgtop" alt="">'
                    . '<h1>' . t("overview-label") . '</h1><span class="description">' . t("overview-hint") . '</span>';
        } else {
            if ($aParams["prj"] <> "all") {
                $oPrj = new project($aParams["prj"]);
                $sReturn.='<img src="' . $sImageBase . $aImages['project'] . '" id="imgtop" alt="">
                    <h1>' . $oPrj->getLabel() . '</h1><span class="description">' . $oPrj->getDescription() . '</span>';
                if (array_key_exists("action", $aParams)) {
                    // $sReturn.='<h2>Aktion: '.$aParams["action"].'</h2>';
                }
            }
        }
        $sReturn.='</div>';
    
        return $sReturn;
    }
    
    /**
     * get h2 headline with action
     * @global type $aParams
     * @global string $sImageBase
     * @global array $aImages
     * @return string
     */
    function getAction() {
        global $aParams, $sImageBase, $aImages;
        $sReturn = '';
        if (array_key_exists("action", $aParams)) {
            $sLabel = $aParams["action"];
            if (array_key_exists("par3", $aParams)) {
                $sLabel.=' :: ' . $aParams["par3"];
            }
            $sReturn.='<h2 class="action ' . $aParams["action"] . '">' . $sLabel . '</h2>';
        } else if (array_key_exists("prj", $aParams)) {
            $sReturn.='<h2 class="action prjhome"> Projekt-Home</h2>';
        }
        return $sReturn;
    }
    
    /**
     * translate function
     * @global type $aConfig
     * @staticvar array $aLang
     * @param string $s text
     * @return string
     */
    function t($s) {
        global $aConfig;
        static $aLang = array();
        
        if (!is_array($aConfig) || !array_key_exists("lang", $aConfig)){
            die("ERROR: \$aConfig[\"lang\"] does not exist.\n");
        }
        if (!count($aLang)) {
            $sLangfile=__DIR__ . "/../../config/lang/" . $aConfig["lang"] . ".json";
            if (!file_exists($sLangfile)){
                die("language file was not found: $sLangfile");
            }
            $aLang = json_decode(file_get_contents($sLangfile), true);
        }
    
        if (!array_key_exists($s, $aLang)) {
            return '<span class="warning">' . $s . '</span>';
        }
        // return $aLang[$s].' ('.$s.')';
        return $aLang[$s];
    }
    
    /**
     * enter user and comment 
     * @global type $aParams
     * @return string
     */
    function enterDeployinfos() {
        global $aParams;
        $sIdUser = "inputUser";
        $sIdComment = "inputComment";
        $sUser = (array_key_exists($sIdUser, $aParams)) ? $aParams[$sIdUser] : "";
        $sComment = (array_key_exists($sIdComment, $aParams)) ? $aParams[$sIdComment] : "";
    
        $sOut = '
            <div class="control-group">
                <label class="control-label" for="inputUser">Benutzername</label>
                <div class="controls">
                    <input type="text" id="inputUser" name="inputUser" placeholder="Benutzername" value="' . $sUser . '">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="inputComment">Kommentar zum Deployment</label>
                <div class="controls">
                    <textarea id= rows="3" id="inputComment" name="inputComment" placeholder="Kommentar">' . $sComment . '</textarea>
                </div>
            </div>
            ';
    
        return $sOut;
    }