diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index a1bce66746de6e8ce22a9e01d8f20ab836597d16..6132350b27afbaf09cb44fcf10a7fe197d28f6d0 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -1129,10 +1129,10 @@ class project extends base /** * check if the given phase is active for this project - * @param type $sPhase - * @return type + * @param string $sPhase + * @return bool */ - public function isActivePhase($sPhase) + public function isActivePhase(string $sPhase): bool { return ( $this->_aPrjConfig && isset($this->_aPrjConfig["phases"][$sPhase]["active"][0]) diff --git a/public_html/deployment/classes/project_gui.class.php b/public_html/deployment/classes/project_gui.class.php index 42bb5d5ba0c66811be06e86dc6c395901293befd..39132ef0688d22e64bee5b2061accd6485740532 100644 --- a/public_html/deployment/classes/project_gui.class.php +++ b/public_html/deployment/classes/project_gui.class.php @@ -13,76 +13,79 @@ require_once 'htmlguielements.class.php'; --------------------------------------------------------------------- 2013-11-08 Axel <axel.hahn@iml.unibe.ch> + (...) + 2024-08-26 Axel php8 only; added variable types; short array syntax ###################################################################### */ /** * class for single project */ // class project { -class projectgui extends project { - - /** - * constructor - * @param string $sId id of the project - public function __construct($sId = false) { - parent::__construct($sId); - $this->_oHtml = new htmlguielements(); - } - */ +class projectgui extends project +{ // ---------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------- /** - * return html code for a div with background color based on a checksum of the given text - * @param string $sText text that is used for checksum; if false ist returns a gray + * Return html code for a div with background color based on a checksum of the given text + * + * @param null|string $sText text that is used for checksum; if false ist returns a gray * @param string $sContent optional: text to show - * @return string + * @return string The HTML code */ - private function _getChecksumDiv($sText, $sContent='', $sBarHeight='3px') { - if ($sText){ - + private function _getChecksumDiv(null|string $sText = '', string $sContent = '', string $sBarHeight = '3px'): string + { + if ($sText) { + // color ranges in decimal values for RGB from ... to - $iFgStart=60; $iFgEnd=160; - $iBgStart=200; $iBgEnd=250; + $iFgStart = 60; + $iFgEnd = 160; + $iBgStart = 200; + $iBgEnd = 250; - $iFgStart=60; $iFgEnd=160; - $iBgStart=190; $iBgEnd=250; + $iFgStart = 60; + $iFgEnd = 160; + $iBgStart = 190; + $iBgEnd = 250; // deivider: 3 digits of md5 will be extracted - $iFgDivider=16*16*16/($iFgEnd-$iFgStart); - $iBgDivider=16*16*16/($iBgEnd-$iBgStart); - - $sHash=md5($sText); - $sColor='' - . 'color: rgba(' - . ($iFgStart + round(hexdec(substr($sHash,0,3))/$iFgDivider)) . ',' - . ($iFgStart + round(hexdec(substr($sHash,3,3))/$iFgDivider)) . ',' - . ($iFgStart + round(hexdec(substr($sHash,6,3))/$iFgDivider)) . ',' + $iFgDivider = 16 * 16 * 16 / ($iFgEnd - $iFgStart); + $iBgDivider = 16 * 16 * 16 / ($iBgEnd - $iBgStart); + + $sHash = md5($sText); + $sColor = '' + . 'color: rgba(' + . ($iFgStart + round(hexdec(substr($sHash, 0, 3)) / $iFgDivider)) . ',' + . ($iFgStart + round(hexdec(substr($sHash, 3, 3)) / $iFgDivider)) . ',' + . ($iFgStart + round(hexdec(substr($sHash, 6, 3)) / $iFgDivider)) . ',' . '1' . ');' - . 'background: rgba(' - . ($iBgStart + round(hexdec(substr($sHash,0,3))/$iBgDivider)) . ',' - . ($iBgStart + round(hexdec(substr($sHash,3,3))/$iBgDivider)) . ',' - . ($iBgStart + round(hexdec(substr($sHash,6,3))/$iBgDivider)) . ',' + . 'background: rgba(' + . ($iBgStart + round(hexdec(substr($sHash, 0, 3)) / $iBgDivider)) . ',' + . ($iBgStart + round(hexdec(substr($sHash, 3, 3)) / $iBgDivider)) . ',' + . ($iBgStart + round(hexdec(substr($sHash, 6, 3)) / $iBgDivider)) . ',' . '1' . ');' - ; + ; } else { $sColor = "color: #888; background: #ccc;"; } - return '<div style="' . $sColor . ' border-top: '.$sBarHeight.' solid;">'.($sContent ? $sContent : ' ').'</div>'; + return '<div style="' . $sColor . ' border-top: ' . $sBarHeight . ' solid;">' . ($sContent ?: ' ') . '</div>'; } /** - * get html code for the colored bar on top of each phase detail items + * Get html code for the colored bar on top of each phase detail items. + * It returns false of revision number was not found in the given phase + place + * * @param string $sPhase phase of a project * @param string $sPlace place in the given phase - * @return string + * @return bool|string The HTML code */ - private function _renderBar($sPhase, $sPlace, $sBarHeight='3px') { + private function _renderBar(string $sPhase, string $sPlace, string $sBarHeight = '3px'): bool|string + { $aDataPhase = $this->getPhaseInfos($sPhase); $aData = $aDataPhase[$sPlace]; if (!array_key_exists("revision", $aData)) { @@ -91,39 +94,47 @@ class projectgui extends project { return $this->_getChecksumDiv($aData["revision"], '', $sBarHeight); } - private function _renderHostsData($aData) { + /** + * Render deploy infos: show hosts and its installed revisions + * @param array $aData deployment metadata + * @return string + */ + private function _renderHostsData(array $aData): string + { $sReturn = ''; - if (array_key_exists('_hosts', $aData)) { - + if (isset($aData['_hosts'])) { + // $sReturn.= print_r($aData['_hosts'], 1); - $sReturn.= '<div class="hosts">' - . '<br><strong>' . t('hosts') . ':</strong><br>' + $sReturn .= '<div class="hosts">' + . '<br><strong>' . t('hosts') . ':</strong><br>' ; foreach ($aData['_hosts'] as $sHostname => $aHostinfos) { $oUpdateDate = date("U", strtotime($aHostinfos['time'])); $iAgeUpdate = round((date("U") - $oUpdateDate) / 60); - $sAge = $iAgeUpdate < 60 * 60 * 13 ? $iAgeUpdate . " min" : "??"; - - $sReturn.= '<div class="host">' - . $this->_getChecksumDiv( - $aHostinfos['_data']['revision'], - $this->_oHtml->getIcon('host').'<br>' . $sHostname - ) - . "($sAge)" - . '</div>' + $sAge = $iAgeUpdate < 60 * 60 * 13 ? "$iAgeUpdate min" : "??"; + + $sReturn .= '<div class="host">' + . $this->_getChecksumDiv( + $aHostinfos['_data']['revision'], + $this->_oHtml->getIcon('host') . '<br>' . $sHostname + ) + . "($sAge)" + . '</div>' ; } - $sReturn.= '</div><div style="clear: both;"></div>'; + $sReturn .= '</div><div style="clear: both;"></div>'; } return $sReturn; } /** - * get html code for list of hosts in a phase + * Get html code for list of hosts in a phase + * * @param string $sPhase phase of a project * @return string */ - private function _renderHosts($sPhase) { + private function _renderHosts(string $sPhase): string + { $aDataPhase = $this->getPhaseInfos($sPhase); if (is_array($aDataPhase) && array_key_exists('deployed', $aDataPhase)) { return $this->_renderHostsData($aDataPhase['deployed']); @@ -132,25 +143,27 @@ class projectgui extends project { } /** - * get html code for list of files in a phase + * Get html code for list of files in a phase + * * @param string $sPhase phase of a project * @return string */ - private function _renderFiles($sPhase) { + private function _renderFiles(string $sPhase): string + { $sReturn = ''; $aFiles = $this->getBuildfilesByPlace($sPhase, 'ready2install'); if (!$aFiles || !$aFiles['filecount']) { return ''; } - $sReturn.='<strong>' . t("filelist") . '</strong> (' . $aFiles['filecount'] . '):<br>'; + $sReturn .= '<strong>' . t("filelist") . '</strong> (' . $aFiles['filecount'] . '):<br>'; foreach ($aFiles['files'] as $sFilename => $aData) { - $sReturn.='<div class="file file-' . $aData['type'] . ' fileext-' . $aData['extension'] . '" title="' . $sFilename . ' (' . $aData['type'] . ')">' - . $aData['icon'] . $sFilename - // . ' ('.$aData['type'].')' - . '</div>' + $sReturn .= '<div class="file file-' . $aData['type'] . ' fileext-' . $aData['extension'] . '" title="' . $sFilename . ' (' . $aData['type'] . ')">' + . $aData['icon'] . $sFilename + // . ' ('.$aData['type'].')' + . '</div>' ; } - $sReturn.='(' . $aFiles['totalsize-hr'] . ')'; + $sReturn .= '(' . $aFiles['totalsize-hr'] . ')'; return $sReturn; } @@ -160,56 +173,57 @@ class projectgui extends project { /** - * render html for a row with td for all places of a phase + * Get html for a row with td for all places of a phase + * * @param string $sPhase phase * @param bool $bActions draw action links (deploy, accept) on/ off * @param bool $bLong use long variant to display infos? - * @return string|boolean + * @return string */ - public function renderAllPhaseDetails($sPhase, $bActions = true, $bLong = true) { - if (!$sPhase) { - return false; - } + public function renderAllPhaseDetails(string $sPhase, bool $bActions = true, bool $bLong = true): string + { if (!$this->isActivePhase($sPhase)) { return ' <td class="td-phase-' . $sPhase . ' td-phase-inactive ' . $this->_aConfig["id"] . '" colspan="' . count($this->_aPlaces) . '"> - <div class="versioninfo center inactive">' . $this->_oHtml->getIcon('sign-info').t('inactive') . '</div> + <div class="versioninfo center inactive">' . $this->_oHtml->getIcon('sign-info') . t('inactive') . '</div> </td>'; } $sRow2 = false; - $aRows = array(); + $aRows = []; $sLastPlace = ''; - + foreach (array_keys($this->_aPlaces) as $sPlace) { $aRows[$sPlace] = $this->renderPhaseDetail($sPhase, $sPlace, $bActions, $bLong); - + // generate ">>" sign for lastly generated td - if ($sLastPlace && array_key_exists("version", $this->_aData["phases"][$sPhase][$sLastPlace]) - && array_key_exists("version", $this->_aData["phases"][$sPhase][$sPlace]) - && $this->_aData["phases"][$sPhase][$sLastPlace]["version"] == $this->_aData["phases"][$sPhase][$sPlace]["version"] - && !$bLong + if ( + $sLastPlace && array_key_exists("version", $this->_aData["phases"][$sPhase][$sLastPlace]) + && array_key_exists("version", $this->_aData["phases"][$sPhase][$sPlace]) + && $this->_aData["phases"][$sPhase][$sLastPlace]["version"] == $this->_aData["phases"][$sPhase][$sPlace]["version"] + && !$bLong ) { $aRows[$sLastPlace] = $this->_renderBar($sPhase, $sPlace) . "»"; } $sLastPlace = $sPlace; } - + foreach (array_keys($this->_aPlaces) as $sPlace) { - $sRow2.='<td class=" td-phase-'.$sPhase.' td-place-'.$sPlace.' td' . $this->_aConfig["id"] . '">' . $aRows[$sPlace] . '</td>'; + $sRow2 .= '<td class=" td-phase-' . $sPhase . ' td-place-' . $sPlace . ' td' . $this->_aConfig["id"] . '">' . $aRows[$sPlace] . '</td>'; } return $sRow2; } /** - * return html code for current project errors by rendering a box per error in $this->_errors + * Get html code for current project errors by rendering a box per error in $this->_errors * @return string */ - public function renderErrorBoxes(){ - $sReturn=''; - if(count($this->_errors)){ - foreach($this->_errors as $sError){ - $sReturn.=$this->_oHtml->getBox("error", $sError); + public function renderErrorBoxes(): string + { + $sReturn = ''; + if (count($this->_errors)) { + foreach ($this->_errors as $sError) { + $sReturn .= $this->_oHtml->getBox("error", $sError); } } return $sReturn; @@ -220,22 +234,25 @@ class projectgui extends project { * fix output of commit message as html * This is a compatibility function for older builds * - * @param string $sMessage git commit message + * @param null|string $sMessage git commit message * @return string */ - public function transformCommitMessage($sMessage){ - if(strstr($sMessage, '<br>Date:')){ - $_aReplace=[ + public function transformCommitMessage(null|string $sMessage): string + { + if (strstr($sMessage, '<br>Date:')) { + $_aReplace = [ '<br>Author:' => "\nAuthor:", '<br>Date:' => "\nDate:", '<br><br>' => "\n\n", ]; - $sMessage=str_replace(array_keys($_aReplace), array_values($_aReplace), $sMessage)." *"; + $sMessage = str_replace(array_keys($_aReplace), array_values($_aReplace), $sMessage) . " *"; } return htmlentities($sMessage); } + /** - * render html code for info link that shows popup with metadata on mouseover + * Get html code for info link that shows popup with metadata on mouseover + * * @param array $aInfos metainfos of the package (from json file) * one of ok=1|error=message - status key * date - timestamp of build @@ -249,63 +266,65 @@ class projectgui extends project { * hpos - horizontal position; one of left|right; default: right * @return string */ - public function renderInfoLink($aInfos, $aOptions = array()) { + public function renderInfoLink(array $aInfos, array $aOptions = []): string + { $sReturn = ''; $bIsError = false; $this->_oHtml = new htmlguielements(); - $sInfos=''; - $sTitle=''; + $sInfos = ''; + $sTitle = ''; if (array_key_exists("title", $aOptions) && $aOptions["title"]) { - $sTitle.=$aOptions["title"]; + $sTitle .= $aOptions["title"]; } if (array_key_exists("ok", $aInfos)) { $sLinktitle = t('infos'); if (array_key_exists("message", $aInfos)) { - $sInfos.=$this->_getChecksumDiv($aInfos["revision"], - $this->_oHtml->getIconByType('calendar') . t('build-from') . ' ' . date("d.m.Y H:i:s", strtotime($aInfos["date"])) . '<br>' - . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aInfos["branch"] . '<br>' - . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aInfos["revision"]) . '<br>' - . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ': ' - ) - . '<pre>' . $this->transformCommitMessage($aInfos["message"]) . '</pre>'; + $sInfos .= $this->_getChecksumDiv( + $aInfos["revision"], + $this->_oHtml->getIconByType('calendar') . t('build-from') . ' ' . date("d.m.Y H:i:s", strtotime($aInfos["date"])) . '<br>' + . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aInfos["branch"] . '<br>' + . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aInfos["revision"]) . '<br>' + . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ': ' + ) + . '<pre>' . $this->transformCommitMessage($aInfos["message"]) . '</pre>'; if (array_key_exists("more", $aOptions)) { - $sInfos.=$aOptions["more"]; + $sInfos .= $aOptions["more"]; } } } else { $bIsError = true; if (!$sTitle) { - $sTitle.=' ' . t('error'); + $sTitle .= ' ' . t('error'); } $sLinktitle = t('error'); - $sInfos = $this->_oHtml->getBox('error', '') . '<p>'.$aInfos["error"].'</p>'; + $sInfos = $this->_oHtml->getBox('error', '') . '<p>' . $aInfos["error"] . '</p>'; } - $sInfos.=$this->_renderHostsData($aInfos, ''); + $sInfos .= $this->_renderHostsData($aInfos, ''); if (array_key_exists("label", $aOptions) && $aOptions["label"]) { - $sLinktitle.=$aOptions["label"]; + $sLinktitle .= $aOptions["label"]; } // render html $sId = 'info' . md5($sInfos); $sReturn = '<a href="#" class="btn ' . ($bIsError ? 'btn-danger' : 'btn-default') . '" title="" - onclick="showIdAsModalMessage(\'' . $sId . '\', \''.$sTitle.'\'); return false;" + onclick="showIdAsModalMessage(\'' . $sId . '\', \'' . $sTitle . '\'); return false;" >' - . $this->_oHtml->getIcon($bIsError ? 'sign-error' : 'sign-info') // ... '<i class="fa fa-info"></i> ' - . $sLinktitle - . '</a><div id="' . $sId . '" style="display: none;" ' - ; + . $this->_oHtml->getIcon($bIsError ? 'sign-error' : 'sign-info') // ... '<i class="fa fa-info"></i> ' + . $sLinktitle + . '</a><div id="' . $sId . '" style="display: none;" ' + ; if (array_key_exists("hpos", $aOptions)) { - $sReturn.=' class="' . $aOptions["hpos"] . '"'; + $sReturn .= ' class="' . $aOptions["hpos"] . '"'; } - $sReturn.='>'; + $sReturn .= '>'; if ($sTitle) { // $sReturn.='<span class="title">' . $sTitle . '</span><br><br>'; } - $sReturn.=$sInfos . '</div>'; + $sReturn .= $sInfos . '</div>'; if ($bIsError) { // $sReturn = '<div class="error">' . $sReturn . '</div>'; @@ -315,52 +334,62 @@ class projectgui extends project { } /** - * render html for a colored link to any project action + * Get html for a colored link to any project action + * * @param string $sFunction name of the action; one of accept|build|cleanup|deploy|new|overview|phase|rollback|setup * @param string $sPhase current phase where to place the link * @return string */ - public function renderLink($sFunction, $sPhase = false, $sVersion = false) { + public function renderLink(string $sFunction, string $sPhase = '', string $sVersion = ''): string + { $sFirst = $this->getNextPhase(); $sNext = $this->getNextPhase($sPhase); - $aLinkdata = array( - 'default' => array('class' => ''), - 'accept' => array('class' => $sNext, + $aLinkdata = [ + 'default' => ['class' => ''], + 'accept' => [ + 'class' => $sNext, 'hint' => sprintf(t("accept-hint"), $sPhase, $sNext), 'label' => t('accept'), - ), - 'build' => array('class' => $sFirst, + ], + 'build' => [ + 'class' => $sFirst, 'hint' => sprintf(t("build-hint"), $sFirst), 'label' => t('build'), 'role' => 'buildProject' - ), - 'cleanup' => array('class' => ''), - 'deploy' => array('class' => $sPhase, + ], + 'cleanup' => ['class' => ''], + 'deploy' => [ + 'class' => $sPhase, 'hint' => sprintf(t("deploy-hint"), $sPhase), 'label' => t('deploy'), - ), - 'new' => array( + ], + 'new' => [ 'hint' => t("new-project-hint"), 'label' => t('new-project'), - ), - 'overview' => array('class' => '', + ], + 'overview' => [ + 'class' => '', 'hint' => t('menu-project-home') . ' [' . $this->getLabel() . ']', 'label' => $this->getLabel() - ), - 'phase' => array('icon' => $this->_oHtml->getIcon('phase'), 'class' => $sPhase, + ], + 'phase' => [ + 'icon' => $this->_oHtml->getIcon('phase'), + 'class' => $sPhase, 'hint' => sprintf(t('phase-details-hint'), $sPhase), 'label' => sprintf(t('phase-details'), $sPhase), - ), - 'rollback' => array('class' => $sPhase, + ], + 'rollback' => [ + 'class' => $sPhase, 'hint' => sprintf(t('rollback-hint'), $sPhase, $sVersion), 'label' => t('rollback') - ), - 'setup' => array('class' => $sPhase, + ], + 'setup' => [ + 'class' => $sPhase, 'hint' => sprintf(t('setup-hint'), $sPhase, $sVersion), 'label' => t('setup'), 'class' => 'btn' - ), - ); + ], + ]; /* if (!$this->oUser->hasRole("project-action-$sFunction")){ // $sClass .= ' disabled'; @@ -372,7 +401,7 @@ class projectgui extends project { $sRole = ''; $sOnMouseover = ''; $sOnMouseout = ''; - switch($sFunction){ + switch ($sFunction) { case 'accept'; $sRole = 'developer'; if ($sNext == "live") { @@ -389,11 +418,11 @@ class projectgui extends project { case 'deploy'; $sRole = 'developer'; $sOnMouseover = '$(\'.td-phase-' . $sPhase . '.td-place-ready2install.td' . $this->_aConfig["id"] . '\').addClass(\'highlight\');' - .'$(\'.td-phase-' . $sPhase . '.td-place-deployed.td' . $this->_aConfig["id"] . '\').addClass(\'highlight\');' - ; + . '$(\'.td-phase-' . $sPhase . '.td-place-deployed.td' . $this->_aConfig["id"] . '\').addClass(\'highlight\');' + ; $sOnMouseout = '$(\'.td-phase-' . $sPhase . '.td-place-ready2install.td' . $this->_aConfig["id"] . '\').removeClass(\'highlight\');' - .'$(\'.td-phase-' . $sPhase . '.td-place-deployed.td' . $this->_aConfig["id"] . '\').removeClass(\'highlight\');' - ; + . '$(\'.td-phase-' . $sPhase . '.td-place-deployed.td' . $this->_aConfig["id"] . '\').removeClass(\'highlight\');' + ; break; } @@ -408,13 +437,13 @@ class projectgui extends project { $sLink = "/deployment/" . ($this->_aConfig["id"] ? $this->_aConfig["id"] : 'all/setup') . "/"; if ($sFunction != "overview") { - $sLink.="$sFunction/"; + $sLink .= "$sFunction/"; } if ($sPhase) { - $sLink.="$sPhase/"; + $sLink .= "$sPhase/"; } if ($sVersion) { - $sLink.="$sVersion/"; + $sLink .= "$sVersion/"; } if (!$this->oUser->hasPermission("project-action-$sFunction")) { // $sClass .= ' disabled'; @@ -422,46 +451,47 @@ class projectgui extends project { } // $sClass='btn ' . (strstr('btn-', $sClass) ? '': 'btn-default ') .$sClass; - return $this->_oHtml->getLinkButton(array( - 'href' => $sLink, - 'title' => $sHint, - 'class' => $sClass, - 'type' => $sFunction, - 'onmouseover' => $sOnMouseover, - 'onmouseout' => $sOnMouseout, - 'label' => $sLabel, - )); + return $this->_oHtml->getLinkButton([ + 'href' => $sLink, + 'title' => $sHint, + 'class' => $sClass, + 'type' => $sFunction, + 'onmouseover' => $sOnMouseover, + 'onmouseout' => $sOnMouseout, + 'label' => $sLabel, + ]); // return '<a href="' . $sLink . '" ' . $sOnMouseover . ' title="' . $sHint . '" class="btn btn-default ' . $sClass . '"><i class="' . $sIconClass . '"></i> ' . $sLabel . '</a>'; } /** - * return html code for the setup form for a new project + * Get html code for the setup form for a new project * @return string */ - public function renderNewProject() { + public function renderNewProject(): string + { global $aParams; if (!$this->oUser->hasPermission("project-action-create")) { return $this->oUser->showDenied(); } - require_once ("formgen.class.php"); + require_once("formgen.class.php"); $i = 0; $sID = array_key_exists("id", $aParams) ? $aParams["id"] : ""; - $aForms = array( - 'setup' => array( - 'meta' => array( + $aForms = [ + 'setup' => [ + 'meta' => [ 'method' => 'POST', 'action' => '?', - ), - 'validate' => array(), - 'form' => array( - 'input' . $i++ => array( + ], + 'validate' => [], + 'form' => [ + 'input' . $i++ => [ 'type' => 'hidden', 'name' => 'setupaction', 'value' => 'create', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'id', 'label' => t("class-project-info-setup-projectId"), @@ -471,29 +501,36 @@ class projectgui extends project { 'size' => 100, 'pattern' => '[a-z0-9\-_]*', 'placeholder' => t("class-project-info-setup-projectId-placeholder"), - ), - ), - ), - ); - $aForms["setup"]["form"]['input' . $i++] = array( + ], + ], + ], + ]; + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'submit', 'name' => 'btnsave', 'label' => t("save"), 'value' => $this->_oHtml->getIcon('sign-ok') . t("save"), - ); + ]; $oForm = new formgen($aForms); return $oForm->renderHtml("setup"); } + /** - * render html for a place of a phase + * Get html for a place of a phase. + * It returns false when + * - phase or place are empty + * - phase is not active + * - place is not valid + * * @param string $sPhase phase * @param string $sPlace name of the place; one of onhold|ready2install|deployed * @param bool $bActions draw action links (deploy, accept) on/ off * @param bool $bLong use long variant to display infos? * @return string|boolean */ - public function renderPhaseDetail($sPhase, $sPlace, $bActions = true, $bLong = true) { + public function renderPhaseDetail(string $sPhase, string $sPlace, bool $bActions = true, bool $bLong = true): bool|string + { if (!$sPhase) { return false; @@ -507,7 +544,7 @@ class projectgui extends project { if (!array_key_exists($sPlace, $this->_aPlaces)) { return false; } - + $sReturn = ''; $aDataPhase = $this->getPhaseInfos($sPhase); $aData = $aDataPhase[$sPlace]; @@ -531,36 +568,36 @@ class projectgui extends project { if ($bLong) { // long display of the revision // $sJsonUrl = $this->_getInfofile($sPhase, $sPlace); - $sReturn .=$this->_getChecksumDiv( - $aData["revision"], - $this->_oHtml->getIconByType('calendar') .' ' . date($sDateFormat, $oPkgDate) . '<br>' - . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aData["branch"] . '<br>' - . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aData["revision"]) . '<br>' - . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ':<br>' - ) + $sReturn .= $this->_getChecksumDiv( + $aData["revision"], + $this->_oHtml->getIconByType('calendar') . ' ' . date($sDateFormat, $oPkgDate) . '<br>' + . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aData["branch"] . '<br>' + . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aData["revision"]) . '<br>' + . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ':<br>' + ) . '<pre>' . $this->transformCommitMessage($aData["message"]) . '</pre>' - ; + ; if ($sPlace == "deployed" && array_key_exists("url", $this->_aPrjConfig["phases"][$sPhase])) { $sUrl = $this->_aPrjConfig["phases"][$sPhase]["url"]; - $sReturn.=$this->_oHtml->getIconByType('link-extern') . ' '. t('url') . ': <a href="' . $sUrl . '">' . $sUrl . '</a><br>'; + $sReturn .= $this->_oHtml->getIconByType('link-extern') . ' ' . t('url') . ': <a href="' . $sUrl . '">' . $sUrl . '</a><br>'; } } else { $sReturn .= $this->_getChecksumDiv( - $aData["revision"], - $this->_oHtml->getIconByType('calendar') .' ' . date($sDateFormat, $oPkgDate) - ); + $aData["revision"], + $this->_oHtml->getIconByType('calendar') . ' ' . date($sDateFormat, $oPkgDate) + ); if ($sPlace == "deployed" && array_key_exists("url", $this->_aPrjConfig["phases"][$sPhase])) { - $sMore = $this->_oHtml->getIconByType('link-extern').' ' - . t('url') - . ': <a href="' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '">' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '</a><br>'; + $sMore = $this->_oHtml->getIconByType('link-extern') . ' ' + . t('url') + . ': <a href="' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '">' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '</a><br>'; } - $sReturn.=' ' . $this->renderInfoLink( - $aData, - [ - 'title' => $this->getLabel() . " :: $sPhase :: $sPlace", - 'more' => $sMore, - ] + $sReturn .= ' ' . $this->renderInfoLink( + $aData, + [ + 'title' => $this->getLabel() . " :: $sPhase :: $sPlace", + 'more' => $sMore, + ] ); } @@ -569,9 +606,9 @@ class projectgui extends project { if (array_key_exists("phases", $this->_aConfig) && array_key_exists($sPhase, $this->_aConfig["phases"])) { // $sReturn .= print_r($this->_aConfig["phases"][$sPhase], true); if (count($this->_getDeploytimes($sPhase))) { - $sReturn .= '<br>'.$this->_oHtml->getIcon('time').t('deploytimes') . ':<br>' - . implode("<br>", array_values($this->_getDeploytimes($sPhase))) - . '<br>'; + $sReturn .= '<br>' . $this->_oHtml->getIcon('time') . t('deploytimes') . ':<br>' + . implode("<br>", array_values($this->_getDeploytimes($sPhase))) + . '<br>'; } if ($bActions) { $sReturn .= ' ' . $this->renderLink("deploy", $sPhase); @@ -599,13 +636,13 @@ class projectgui extends project { // $this->_getChecksumDiv($aData["revision"]) } else { if (array_key_exists("error", $aData)) { - $sReturn.='' - . $this->renderInfoLink(array('error' => $aData["error"]), array()) + $sReturn .= '' + . $this->renderInfoLink(['error' => $aData["error"], [] ]) ; } else if (array_key_exists("warning", $aData)) { - $sReturn.= '<div class="warning">'.$this->_oHtml->getIcon('sign-info'). t('warning') . ':<br>' . $aData["warning"] . '</div>'; + $sReturn .= '<div class="warning">' . $this->_oHtml->getIcon('sign-info') . t('warning') . ':<br>' . $aData["warning"] . '</div>'; } else { - + // OK = 1 ... for the queue we show no hint return ''; /* @@ -616,43 +653,44 @@ class projectgui extends project { */ } } // if - // } // for return $sReturn; } /** - * render html for the project overview; it shows the defined phases for + * Get html for the project overview; it shows the defined phases for * the project as a table - * @return type + * @return string */ - public function renderPhaseInfo() { + public function renderPhaseInfo(): string + { $sRow1 = false; $sRow2 = false; - $renderAdminLTE=new renderadminlte(); + $renderAdminLTE = new renderadminlte(); - $iWidth=min(12 / count($this->getActivePhases()), 4); + $iWidth = min(12 / count($this->getActivePhases()), 4); foreach ($this->getActivePhases() as $sPhase) { - $sRow1.=$renderAdminLTE->addCol( + $sRow1 .= $renderAdminLTE->addCol( '<table class="nomargin"><tr><th class="' . $sPhase . ' tdphase">' . $sPhase . '</th></tr></table>' , - $iWidth); - - $sDetails=t('url') . ': <a href="' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '">' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '</a><br>' - . '<br>' . t('deploytimes') . ':<br>'; + $iWidth + ); + + $sDetails = t('url') . ': <a href="' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '">' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '</a><br>' + . '<br>' . t('deploytimes') . ':<br>'; if (count($this->_getDeploytimes($sPhase))) { - $sDetails.=implode("<br>", $this->_getDeploytimes($sPhase)); + $sDetails .= implode("<br>", $this->_getDeploytimes($sPhase)); } else { - $sDetails.=t('deploytimes-immediately'); + $sDetails .= t('deploytimes-immediately'); } - $sDetails.='<br>' . $this->renderLink("phase", $sPhase) - . $this->_renderHosts($sPhase) - . '<br>' - . $this->_renderFiles($sPhase) - ; + $sDetails .= '<br>' . $this->renderLink("phase", $sPhase) + . $this->_renderHosts($sPhase) + . '<br>' + . $this->_renderFiles($sPhase) + ; - $sRow2.=$renderAdminLTE->addCol( - $renderAdminLTE->getCard(array ( + $sRow2 .= $renderAdminLTE->addCol( + $renderAdminLTE->getCard([ 'class' => $sPhase, 'variant' => '', 'tb-remove' => 1, @@ -661,93 +699,94 @@ class projectgui extends project { 'tools' => '', 'text' => $sDetails, 'footer' => '', - )), + ]), $iWidth ); } return '' - .$renderAdminLTE->addRow($sRow1) - .$renderAdminLTE->addRow($sRow2) - ; + . $renderAdminLTE->addRow($sRow1) + . $renderAdminLTE->addRow($sRow2) + ; } /** - * render html for a row with td for all places (first row) + * Get html for a row with td for all places (first row) * @param string $sPhase phase (just needed for coloring) * @return string */ - public function renderPlacesAsTd($sPhase) { + public function renderPlacesAsTd(string $sPhase): string + { $sRow1 = ''; foreach (array_keys($this->_aPlaces) as $sPlace) { - $sRow1.='<td class="' . $sPhase . ' ' . $this->_aConfig["id"] . ' tdphase">' . t($sPlace) . '</td>'; + $sRow1 .= '<td class="' . $sPhase . ' ' . $this->_aConfig["id"] . ' tdphase">' . t($sPlace) . '</td>'; } return $sRow1; } /** - * return html code for the setup form of an exsiting project + * Get html code for the setup form of an exsiting project * @return string */ - public function renderProjectSetup() { + public function renderProjectSetup(): string + { if (!$this->oUser->hasPermission("project-action-setup")) { return $this->oUser->showDenied(); } $sMessages = ''; - require_once ("formgen.class.php"); + require_once("formgen.class.php"); + $aSelectProjectGroup = [ + 'type' => 'select', + 'name' => 'projectgroup', + 'label' => t("projectgroup"), + 'options' => [ + OPTION_NONE => [ + 'label' => t('none'), + ], + '' => [ + 'label' => '- - - - - - - - - - - - - - - - - - - - ', + ], + ], + ]; + foreach ($this->_aConfig['projectgroups'] as $sGroupid => $sGroupLabel) { + $bActive = $this->getProjectGroup() === $sGroupid; + $aSelectProjectGroup['options'][$sGroupid] = [ + 'label' => $sGroupLabel, + 'selected' => $bActive ? 'selected' : false, + ]; + } - $aSelectProjectGroup = array( - 'type' => 'select', - 'name' => 'projectgroup', - 'label' => t("projectgroup"), - 'options' => array( - OPTION_NONE => array( - 'label' => t('none'), - ), - '' => array( - 'label' => '- - - - - - - - - - - - - - - - - - - - ', - ), - ), - ); - foreach($this->_aConfig['projectgroups'] as $sGroupid=>$sGroupLabel){ - $bActive=$this->getProjectGroup() === $sGroupid; - $aSelectProjectGroup['options'][$sGroupid] = array( - 'label' => $sGroupLabel, - 'selected' => $bActive ? 'selected' : false, - ); - } - - $aSelectSlack = array( - 'type' => 'hidden', - 'name' => 'messenger[slack]', - 'value' => false, - ); + $aSelectSlack = [ + 'type' => 'hidden', + 'name' => 'messenger[slack]', + 'value' => false, + ]; if ( - isset($this->_aConfig['messenger']['slack']['presets']) - && count($this->_aConfig['messenger']['slack']['presets']) + isset($this->_aConfig['messenger']['slack']['presets']) + && count($this->_aConfig['messenger']['slack']['presets']) ) { - $aSelectSlack = array( + $aSelectSlack = [ 'type' => 'select', 'name' => 'messenger[slack]', 'label' => t("messenger-slack"), - 'options' => array( - OPTION_NONE => array( + 'options' => [ + OPTION_NONE => [ 'label' => t('none'), - ), - '' => array( + ], + '' => [ 'label' => '- - - - - - - - - - - - - - - - - - - - ', - ), - ), - ); - foreach($this->_aConfig['messenger']['slack']['presets'] as $sSlackUrl=>$aSlackCfg){ - $bActive=$this->_aPrjConfig['messenger']['slack'] === $sSlackUrl; - $aSelectSlack['options'][$sSlackUrl] = array( + ], + ], + ]; + foreach ($this->_aConfig['messenger']['slack']['presets'] as $sSlackUrl => $aSlackCfg) { + $bActive = $this->_aPrjConfig['messenger']['slack'] === $sSlackUrl; + $aSelectSlack['options'][$sSlackUrl] = [ 'label' => array_key_exists('label', $aSlackCfg) ? $aSlackCfg['label'] : $sSlackUrl, 'selected' => $bActive ? 'selected' : false, - ); + ]; } - + } // ---------- Build plugins /* @@ -793,74 +832,74 @@ class projectgui extends project { */ // ---------- /Build plugins - + // ---------- Rollout plugins - $aRollout = array( - 'project-select' => array( + $aRollout = [ + 'project-select' => [ 'type' => 'radio', 'name' => 'deploy[enabled_rollout_plugin]', 'label' => t("deploy-rollout-plugin"), - ), + ], 'project-config' => '', - ); - foreach (array_keys($this->getConfiguredPlugins('rollout')) as $sPluginName){ + ]; + foreach (array_keys($this->getConfiguredPlugins('rollout')) as $sPluginName) { - $sPluginFile=$this->_getPluginFilename('rollout', $sPluginName); + $sPluginFile = $this->_getPluginFilename('rollout', $sPluginName); $TmpRolloutPlugin = false; - $sMyClassname='rollout_'. $sPluginName; - $sMyDivId='rollout-'. $sPluginName.'-config'; - $sMyDivClass='rolloutconfigdiv'; - $sMyDivClassActive='rolloutconfigdiv-'. $sPluginName; - $bActive=$sPluginName === $this->oRolloutPlugin->getId(); - - if(file_exists($sPluginFile)){ - try{ + $sMyClassname = 'rollout_' . $sPluginName; + $sMyDivId = 'rollout-' . $sPluginName . '-config'; + $sMyDivClass = 'rolloutconfigdiv'; + $sMyDivClassActive = 'rolloutconfigdiv-' . $sPluginName; + $bActive = $sPluginName === $this->oRolloutPlugin->getId(); + + if (file_exists($sPluginFile)) { + try { include_once $this->_getPluginFilename('rollout', $sPluginName); - $TmpRolloutPlugin = new $sMyClassname(array( - 'lang'=>$this->_aConfig['lang'], - 'phase'=>false, - 'globalcfg'=>$this->_aConfig['plugins']['rollout'][$sPluginName], - 'projectcfg'=>$this->_aPrjConfig, - )); - $aRollout['project-select']['options'][$sPluginName]=array( - 'label' => $TmpRolloutPlugin->getName(), - 'checked' => $bActive, - 'onclick' => '$(\'.'.$sMyDivClass.'\').hide(); $(\'.' . $sMyDivClassActive . '\').show();', - ); - - $aRollout['project-config'].='' - . '<div id="'.$sMyDivId.'" class="'.$sMyDivClass.' '.$sMyDivClassActive.'"' - . ($bActive ? '' : ' style="display: none;"' ) - . '>' - . $TmpRolloutPlugin->renderFormdata4Project() - . '</div>' - ; - + $TmpRolloutPlugin = new $sMyClassname([ + 'lang' => $this->_aConfig['lang'], + 'phase' => false, + 'globalcfg' => $this->_aConfig['plugins']['rollout'][$sPluginName], + 'projectcfg' => $this->_aPrjConfig, + ]); + $aRollout['project-select']['options'][$sPluginName] = [ + 'label' => $TmpRolloutPlugin->getName(), + 'checked' => $bActive, + 'onclick' => '$(\'.' . $sMyDivClass . '\').hide(); $(\'.' . $sMyDivClassActive . '\').show();', + ]; + + $aRollout['project-config'] .= '' + . '<div id="' . $sMyDivId . '" class="' . $sMyDivClass . ' ' . $sMyDivClassActive . '"' + . ($bActive ? '' : ' style="display: none;"') + . '>' + . $TmpRolloutPlugin->renderFormdata4Project() + . '</div>' + ; + // generate form firlds for each phase - foreach(array_keys($this->getPhases()) as $sMyPhase){ - $aRollout[$sMyPhase].='' - . '<div id="'.$sMyDivId.'-'.$sMyPhase.'" class="'.$sMyDivClass.' '.$sMyDivClassActive.'"' - . ($bActive ? '' : ' style="display: none;"' ) + foreach (array_keys($this->getPhases()) as $sMyPhase) { + $aRollout[$sMyPhase] .= '' + . '<div id="' . $sMyDivId . '-' . $sMyPhase . '" class="' . $sMyDivClass . ' ' . $sMyDivClassActive . '"' + . ($bActive ? '' : ' style="display: none;"') . '>' - . $TmpRolloutPlugin->renderFormdata4Phase($sMyPhase) + . $TmpRolloutPlugin->renderFormdata4Phase($sMyPhase) . '</div>' - ; + ; } } catch (Exception $ex) { } } else { - $aRollout['project-select']['options'][$sPluginName]=array( - 'label' => 'not found: <span class="error">' . $sMyClassname . '</span>', - 'checked' => false, - 'disabled' => "disabled", - ); + $aRollout['project-select']['options'][$sPluginName] = [ + 'label' => 'not found: <span class="error">' . $sMyClassname . '</span>', + 'checked' => false, + 'disabled' => "disabled", + ]; + - } } // ---------- /Rollout plugins - + $aForemanHostgroups = false; $iForemanHostgroupDefault = false; $sForemanHostgroupDefault = false; @@ -872,35 +911,36 @@ class projectgui extends project { // $oForeman->setDebug(1); // $oForeman->selfcheck(); die(__FUNCTION__); - $aForemanHostgroups = $oForeman->read(array( - 'request' => array( - array('hostgroups'), - // array('operatingsystems',4), - ), - 'response' => array( - 'id', 'title' - ), - )); - $aSelectForemanGroups = array( + $aForemanHostgroups = $oForeman->read([ + 'request' => [ + ['hostgroups'], + // ['operatingsystems',4], + ], + 'response' => [ + 'id', + 'title' + ], + ]); + $aSelectForemanGroups = [ 'type' => 'select', 'name' => 'deploy[foreman][hostgroup]', 'label' => $this->_oHtml->getIcon('foreman') . t("foreman-hostgroup"), - 'options' => array( - OPTION_NONE => array( + 'options' => [ + OPTION_NONE => [ 'label' => t('none'), - ), - '' => array( + ], + '' => [ 'label' => '- - - - - - - - - - - - - - - - - - - - ', - ), - ), - ); + ], + ], + ]; if ($aForemanHostgroups && count($aForemanHostgroups)) { foreach ($aForemanHostgroups as $aItem) { - $bActive=$iForemanHostgroupDefault === (int) $aItem['id']; - $aSelectForemanGroups['options'][$aItem['id']] = array( + $bActive = $iForemanHostgroupDefault === (int) $aItem['id']; + $aSelectForemanGroups['options'][$aItem['id']] = [ 'label' => $aItem['title'], 'selected' => $bActive ? 'selected' : false, - ); + ]; $sForemanHostgroupDefault = $bActive ? $aItem['title'] : $sForemanHostgroupDefault; } } @@ -910,87 +950,87 @@ class projectgui extends project { $i = 0; $aPrefixItem = count($this->getVersions()) ? - array( - 'type' => 'markup', - 'value' => '<div class="form-group"> + [ + 'type' => 'markup', + 'value' => '<div class="form-group"> <label class="col-sm-2">' . t('fileprefix') . '</label> <div class="col-sm-10"> <input id="inputprefix" type="hidden" name="fileprefix" value="' . $this->_aPrjConfig["fileprefix"] . '"> ' . $this->_aPrjConfig["fileprefix"] . ' </div></div> ', - ) : array( - 'type' => 'text', - 'name' => 'fileprefix', - // 'disabled' => 'disabled', - 'label' => t('fileprefix-label'), - 'value' => $this->_aPrjConfig["fileprefix"], - 'required' => 'required', - 'validate' => 'isastring', - 'pattern' => '[a-z0-9\-_]*', - 'size' => 100, - 'placeholder' => '', - ); + ] : [ + 'type' => 'text', + 'name' => 'fileprefix', + // 'disabled' => 'disabled', + 'label' => t('fileprefix-label'), + 'value' => $this->_aPrjConfig["fileprefix"], + 'required' => 'required', + 'validate' => 'isastring', + 'pattern' => '[a-z0-9\-_]*', + 'size' => 100, + 'placeholder' => '', + ]; // detect access to repo url - $aBranches=$this->getRemoteBranches(true); + $aBranches = $this->getRemoteBranches(true); // $aRepodata = $this->getRepoRevision(); // if (is_array($aRepodata) && array_key_exists("message", $aRepodata)) { if (is_array($aBranches) && count($aBranches)) { $sRepoCheck = '<span class="ok">' . sprintf(t('class-project-info-repoaccess'), count($aBranches)) . '</span>'; } else { - $sRepoError=sprintf(t('class-project-error-no-repoaccess'), $aRepodata["error"]); + $sRepoError = sprintf(t('class-project-error-no-repoaccess'), $aRepodata["error"]); $sRepoCheck = '<span class="error">' . $sRepoError . '</span>'; - $sMessages.=$this->_oHtml->getBox("error", $sRepoError); + $sMessages .= $this->_oHtml->getBox("error", $sRepoError); } // generate datalist with exisating ssh keys for auth field $sAuthListitems = ''; foreach ($this->_getSshKeys() as $sKey) { - $sAuthListitems.='<option value="' . $sKey . '">'; + $sAuthListitems .= '<option value="' . $sKey . '">'; } - $aForms = array( - 'setup' => array( - 'meta' => array( + $aForms = [ + 'setup' => [ + 'meta' => [ 'method' => 'POST', 'action' => '?', - ), - 'validate' => array(), - 'form' => array( - 'input' . $i++ => array( + ], + 'validate' => [], + 'form' => [ + 'input' . $i++ => [ 'type' => 'hidden', 'name' => 'setupaction', 'value' => 'save', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'hidden', 'name' => 'id', 'value' => $this->_aConfig["id"], - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'markup', 'value' => '<div class="tabbable"> <ul class="nav nav-tabs"> - <li class="active"><a href="#tab1" class="nav-link active" data-toggle="tab" aria-selected="1">' . $this->_oHtml->getIcon('list').t('setup-metadata') . '</a></li> - <li><a href="#tab2" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('repository').t('repositoryinfos') . '</a></li> + <li class="active"><a href="#tab1" class="nav-link active" data-toggle="tab" aria-selected="1">' . $this->_oHtml->getIcon('list') . t('setup-metadata') . '</a></li> + <li><a href="#tab2" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('repository') . t('repositoryinfos') . '</a></li> - <li><a href="#tab3" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('deploy-configfile').t('deploy-configfile') . '</a></li> - <li><a href="#tab4" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('deploy-rollout-plugin').t('deploy-rollout-plugin') . '</a></li> - <li><a href="#tab5" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('phase').t('phases') . '</a></li> - <li><a href="#tab6" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('raw-data').t('raw-data') . '</a></li> + <li><a href="#tab3" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('deploy-configfile') . t('deploy-configfile') . '</a></li> + <li><a href="#tab4" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('deploy-rollout-plugin') . t('deploy-rollout-plugin') . '</a></li> + <li><a href="#tab5" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('phase') . t('phases') . '</a></li> + <li><a href="#tab6" class="nav-link" data-toggle="tab">' . $this->_oHtml->getIcon('raw-data') . t('raw-data') . '</a></li> </ul> <div class="tab-content"> <div class="tab-pane fade active show" id="tab1"> <br> ', - ), + ], // -------------------------------------------------- // Tab for metadata // ------------------------------------------------- - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'text', 'name' => 'label', 'label' => t('projectname'), @@ -999,8 +1039,8 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => 'Projekt', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'description', 'label' => t('projectdescription'), @@ -1009,8 +1049,8 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'contact', 'label' => t('contact'), @@ -1019,15 +1059,15 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), + ], 'input' . $i++ => $aSelectProjectGroup, - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => '<p>' . t('messenger') . '</p>', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'messenger[email]', 'label' => t("messenger-email"), @@ -1036,19 +1076,19 @@ class projectgui extends project { 'size' => 100, 'placeholder' => '', 'autocomplete' => 'off', - ), - + ], + 'input' . $i++ => $aSelectSlack, - + // -------------------------------------------------- // Tab soources repository & build // -------------------------------------------------- - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => ' </div><div class="tab-pane fade" id="tab2"> <p>' . t('setup-hint-build') . '</p>', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'build[type]', 'label' => t("build-type"), @@ -1057,8 +1097,8 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'build[url]', 'label' => t("repository-url"), @@ -1067,8 +1107,8 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'build[auth]', 'label' => t("repository-auth"), @@ -1078,19 +1118,19 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'markup', 'value' => '<datalist id="listauth">' . $sAuthListitems . '</datalist>', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'markup', 'value' => '<div class="form-group">' - . '<label class="col-sm-2"> </label><div class="col-sm-10">' - . $sRepoCheck - . '</div></div>', - ), - 'input' . $i++ => array( + . '<label class="col-sm-2"> </label><div class="col-sm-10">' + . $sRepoCheck + . '</div></div>', + ], + 'input' . $i++ => [ 'type' => 'text', 'name' => 'build[webaccess]', 'label' => t("repository-urlwebgui"), @@ -1098,48 +1138,48 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), + ], 'input' . $i++ => $aPrefixItem, - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => '<div style="clear: both"></div>', - ), + ], // task#1498 - handle project without "public" directory - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'checkbox', 'name' => 'build[haspublic]', 'label' => t("repository-has-public-dir"), 'required' => false, 'validate' => 'isastring', - 'options' => array( - '1' => array( + 'options' => [ + '1' => [ 'label' => t("yes"), 'checked' => (array_key_exists('haspublic', $this->_aPrjConfig["build"]) ? $this->_aPrjConfig["build"]["haspublic"] : 0), - ), - ), - ), + ], + ], + ], // -------------------------------------------------- // Tab for config and API key // -------------------------------------------------- - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => ' </div><div class="tab-pane fade" id="tab3"> <p>' . t('deploy-configfile-hint') . '</p>', - ), - 'textarea' . $i++ => array( + ], + 'textarea' . $i++ => [ 'type' => 'textarea', 'name' => 'deploy[configfile]', 'label' => t("deploy-configfile"), 'value' => $this->_aPrjConfig['deploy']["configfile"], // 'required' => 'required', - 'validate' => 'isastring', + 'validate' => 'isastring', 'cols' => 100, 'rows' => 10, 'placeholder' => 'export myvariable="hello world"', - ), - - 'input' . $i++ => array( + ], + + 'input' . $i++ => [ 'type' => 'text', 'name' => 'api[secret]', 'label' => t("api-secret"), @@ -1147,56 +1187,56 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', - ), - 'input' . $i++ => array( + ], + 'input' . $i++ => [ 'type' => 'markup', 'value' => '<div class="col-sm-12">' - . '<p>' . t('api-secret-hint') . '<br>' - . '<a href="#" class="btn btn-default" onclick="$(\'#input'.($i-2).'\').val(generateSecret(64)); return false">'.t("api-secret-generate").'</a>' - . '</p></div>', - ), - + . '<p>' . t('api-secret-hint') . '<br>' + . '<a href="#" class="btn btn-default" onclick="$(\'#input' . ($i - 2) . '\').val(generateSecret(64)); return false">' . t("api-secret-generate") . '</a>' + . '</p></div>', + ], + // -------------------------------------------------- // Tab rollout plugin // -------------------------------------------------- - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => ' </div><div class="tab-pane fade" id="tab4"> <p>' . t('deploy-rollout-plugin-hint') . '</p>', - ), + ], // select box for active rollout plugin $aRollout['project-select'], - + // project based config - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => '' . '<hr>' - .'<label class="col-sm-2">'.t('deploy-rollout-plugin-config') .'</label>' - .'<div class="col-sm-10">'. $aRollout['project-config'].'</div>' - ), + . '<label class="col-sm-2">' . t('deploy-rollout-plugin-config') . '</label>' + . '<div class="col-sm-10">' . $aRollout['project-config'] . '</div>' + ], // -------------------------------------------------- - 'input' . $i++ => array( + 'input' . $i++ => [ 'type' => 'markup', 'value' => ' </div><div class="tab-pane fade" id="tab5"> <p>' . sprintf(t("class-project-info-setup-phaseinfos"), $this->getNextPhase()) . '</p>', - ), - ), - ), - ); + ], + ], + ], + ]; // -------------------------------------------------- // Tab for phases // -------------------------------------------------- if ($aSelectForemanGroups) { - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', - 'value' => '<strong>'.t("defaults-all-phases").'</strong><br><br>', - ); + 'value' => '<strong>' . t("defaults-all-phases") . '</strong><br><br>', + ]; $aForms["setup"]["form"]['input' . $i++] = $aSelectForemanGroups; - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '<br><br>', - ); + ]; } foreach (array_keys($this->getPhases()) as $sPhase) { @@ -1225,50 +1265,50 @@ class projectgui extends project { if ($aSelectForemanGroups) { $iForemanHostgroup = (int) $this->_aPrjConfig['phases'][$sPhase]['foreman-hostgroup']; - $aSelectForemanHostGroup = array( + $aSelectForemanHostGroup = [ 'type' => 'select', 'name' => 'phases[' . $sPhase . '][foreman-hostgroup]', 'label' => $this->_oHtml->getIcon('foreman') . t("foreman-hostgroup"), - 'options' => array( - OPTION_DEFAULT => array( + 'options' => [ + OPTION_DEFAULT => [ 'label' => t('default') . ' (' . $sForemanHostgroupDefault . ')', 'selected' => $iForemanHostgroup === OPTION_DEFAULT ? 'selected' : false, - ), - OPTION_NONE => array( + ], + OPTION_NONE => [ 'label' => t('none'), 'selected' => $iForemanHostgroup === OPTION_NONE ? 'selected' : false, - ), - '' => array( + ], + '' => [ 'label' => '- - - - - - - - - - - - - - - - - - - - ', - ), - ), - ); + ], + ], + ]; if (is_array($aForemanHostgroups) && count($aForemanHostgroups)) { foreach ($aForemanHostgroups as $aItem) { - $aSelectForemanHostGroup['options'][$aItem['id']] = array( + $aSelectForemanHostGroup['options'][$aItem['id']] = [ 'label' => $aItem['title'], 'selected' => ($iForemanHostgroup === $aItem['id']) ? 'selected' : false, - ); + ]; } } } - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '' - // .'<pre>'.print_r($this->_aPrjConfig["phases"][$sPhase], 1).'</pre>' - /* - . '<a class="'.$sPhase.'">' - . t("phase") . ' ' . $sPhase - . '</a>' - */ - . '<table class="table">' - . '<tbody>' - . '<tr><th class="' . $sPhase . '">' . $this->_oHtml->getIcon('phase') . t("phase") . ' ' . $sPhase . '</th></tr>' - . '<tr><td class="' . ($bActivePhase ? $sPhase : '') . '">' - . '' - ); + // .'<pre>'.print_r($this->_aPrjConfig["phases"][$sPhase], 1).'</pre>' + /* + . '<a class="'.$sPhase.'">' + . t("phase") . ' ' . $sPhase + . '</a>' + */ + . '<table class="table">' + . '<tbody>' + . '<tr><th class="' . $sPhase . '">' . $this->_oHtml->getIcon('phase') . t("phase") . ' ' . $sPhase . '</th></tr>' + . '<tr><td class="' . ($bActivePhase ? $sPhase : '') . '">' + . '' + ]; - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'checkbox', 'name' => 'phases[' . $sPhase . '][active]', 'label' => t("phase-is-active"), @@ -1277,20 +1317,20 @@ class projectgui extends project { 'validate' => 'isastring', // 'size' => 100, // 'placeholder' => '...', - 'options' => array( - '1' => array( + 'options' => [ + '1' => [ 'label' => t("yes"), 'checked' => $bActivePhase, 'onclick' => '$(\'#' . $sDivId4PhaseSettings . '\').css(\'display\', (this.checked ? \'block\' : \'none\') )', - ), - ), - ); - $aForms["setup"]["form"]['input' . $i++] = array( + ], + ], + ]; + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '' - . '<div id="' . $sDivId4PhaseSettings . '" ' . ($bActivePhase ? '' : ' style="display: none;"') . '>' - ); - $aForms["setup"]["form"]['input' . $i++] = array( + . '<div id="' . $sDivId4PhaseSettings . '" ' . ($bActivePhase ? '' : ' style="display: none;"') . '>' + ]; + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'text', 'name' => 'phases[' . $sPhase . '][url]', 'label' => $this->_oHtml->getIcon('url') . t("url-project-website"), @@ -1299,8 +1339,8 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => 'https://' . $sPhase . '.[' . t("project") . '].[...]/', - ); - $aForms["setup"]["form"]['input' . $i++] = array( + ]; + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'radio', 'name' => 'phases[' . $sPhase . '][deploymethod]', 'label' => $this->_oHtml->getIcon('method') . t("deploymethod"), @@ -1309,46 +1349,46 @@ class projectgui extends project { 'validate' => 'isastring', // 'size' => 100, // 'placeholder' => '...', - 'options' => array( - 'none' => array( + 'options' => [ + 'none' => [ 'label' => t("deploymethod-none"), 'checked' => $sDeploymethod === "none", 'onclick' => '$(\'#' . $sDivId4TargetHosts . '\').css(\'display\', (this.checked ? \'none\' : \'block\') )', - ), - 'rolloutplugin' => array( + ], + 'rolloutplugin' => [ // 'label' => t("deploymethod-puppet").' - '. $this->oRolloutPlugin->getName(), 'label' => t("deploymethod-rolloutplugin"), 'checked' => $sDeploymethod === "rolloutplugin", 'onclick' => '$(\'#' . $sDivId4TargetHosts . '\').css(\'display\', (this.checked ? \'block\' : \'none\') )', - ), - /* - * see deploy method to handle an action - 'sshproxy' => array( - 'label' => t("deploymethod-sshproxy"), - 'checked' => $sDeploymethod==="sshproxy", - 'onclick' => '$(\'#'.$sDivId4TargetHosts.'\').css(\'display\', (this.checked ? \'block\' : \'none\') )', - ), - */ - ), - ); - + ], + /* + * see deploy method to handle an action + 'sshproxy' => [ + 'label' => t("deploymethod-sshproxy"), + 'checked' => $sDeploymethod==="sshproxy", + 'onclick' => '$(\'#'.$sDivId4TargetHosts.'\').css(\'display\', (this.checked ? \'block\' : \'none\') )', + ], + */ + ], + ]; + - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '' - . '<div id="' . $sDivId4TargetHosts . '" ' . ($sDeploymethod !== "none" ? '' : ' style="display: none;"') . '>' - ); - + . '<div id="' . $sDivId4TargetHosts . '" ' . ($sDeploymethod !== "none" ? '' : ' style="display: none;"') . '>' + ]; + // rollout plugin: phase specific overrides - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '' // . '<hr>' - .'<label class="col-sm-2">'.t('deploy-rollout-plugin-config') .'</label>' - .'<div class="col-sm-10">'.$aRollout[$sPhase].'</div>' - ); - - $aForms["setup"]["form"]['input' . $i++] = array( + . '<label class="col-sm-2">' . t('deploy-rollout-plugin-config') . '</label>' + . '<div class="col-sm-10">' . $aRollout[$sPhase] . '</div>' + ]; + + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'text', 'name' => 'phases[' . $sPhase . '][hosts]', 'label' => $this->_oHtml->getIcon('host') . t("phase-targethosts"), @@ -1357,7 +1397,7 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => 'FQDN1,FQDN2', - ); + ]; /* if ($sPuppethost) { @@ -1377,18 +1417,18 @@ class projectgui extends project { } else { $sOut = '<span class="ok">' . sprintf(t("class-project-info-setup-ssh-and-puppet-ok"), $sPuppethost) . '</span>'; } - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '<div class="form-group">' . '<label class="col-sm-2"> </label><div class="col-sm-10">' . $sOut . '</div></div>', - ); + ]; } */ // when to deploy - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'text', 'name' => 'phases[' . $sPhase . '][deploytimes]', 'label' => $this->_oHtml->getIcon('time') . t("deploytimes"), @@ -1397,92 +1437,94 @@ class projectgui extends project { 'validate' => 'isastring', 'size' => 100, 'placeholder' => isset($this->_aConfig["phases"][$sPhase]["deploytimes"]) ? implode(", ", $this->_aConfig["phases"][$sPhase]["deploytimes"]) : '', - ); - $aForms["setup"]["form"]['input' . $i++] = array( + ]; + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '' - . '</div>' - ); + . '</div>' + ]; if ($aSelectForemanGroups) { $aForms["setup"]["form"]['input' . $i++] = $aSelectForemanHostGroup; } - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '' - . '</div>' - ); // close div for active phase + . '</div>' + ]; // close div for active phase - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '</td></tr></tbody></table>', - ); + ]; } // END: loop over phases // -------------------------------------------------- // Tab for raw data // -------------------------------------------------- - - $sRolloutDebug='<hr>DEBUG:<br>'; + + $sRolloutDebug = '<hr>DEBUG:<br>'; foreach (array_keys($this->getPhases()) as $sPhase) { - if ($this->isActivePhase($sPhase)){ - $sRolloutDebug.='<strong>'.$sPhase.'</strong>' - . '<pre>Config = '.print_r($this->oRolloutPlugin->getConfig($sPhase, 1), 1).'</pre>' - . '<pre>Commands = '.print_r($this->oRolloutPlugin->getDeployCommands($sPhase, 1), 1).'</pre>' + if ($this->isActivePhase($sPhase)) { + $sRolloutDebug .= '<strong>' . $sPhase . '</strong>' + . '<pre>Config = ' . print_r($this->oRolloutPlugin->getConfig($sPhase, 1), 1) . '</pre>' + . '<pre>Commands = ' . print_r($this->oRolloutPlugin->getDeployCommands($sPhase, 1), 1) . '</pre>' ; } } - $aForms["setup"]["form"]['input' . $i++] = array( + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'markup', 'value' => '</div>' - + . '<div class="tab-pane fade" id="tab6">' - . '<br><pre>'.print_r($this->_aPrjConfig, 1).'</pre>' + . '<br><pre>' . print_r($this->_aPrjConfig, 1) . '</pre>' . $sRolloutDebug . '</div>' - - . '</div>' - . '</div>' - . '<div style="clear: both; margin-bottom: 1em;"></div>' - - - . '<hr>', - ); - $aForms["setup"]["form"]['input' . $i++] = array( + + . '</div>' + . '</div>' + . '<div style="clear: both; margin-bottom: 1em;"></div>' + + + . '<hr>', + ]; + $aForms["setup"]["form"]['input' . $i++] = [ 'type' => 'submit', 'name' => 'btnsave', 'label' => t("save"), - 'value' => $this->_oHtml->getIcon('sign-ok').t("save"), - ); + 'value' => $this->_oHtml->getIcon('sign-ok') . t("save"), + ]; $oForm = new formgen($aForms); return $sMessages . $oForm->renderHtml("setup"); } /** - * return html code for the installed version in the repository + * Get html code for the installed version in the repository * @param boolean $bRefresh optional: refresh flag; default: use cached information * @return string */ - public function renderRepoInfo($bRefresh=false) { + public function renderRepoInfo(bool $bRefresh = false): string + { $sReturn = ""; switch ($this->_aPrjConfig["build"]["type"]) { case "git": $aRepodata = $this->getRepoRevision($bRefresh); if (array_key_exists("revision", $aRepodata)) { - $sReturn.=$this->_getChecksumDiv($aRepodata["revision"], + $sReturn .= $this->_getChecksumDiv( + $aRepodata["revision"], $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . (array_key_exists("branch", $aRepodata) ? $aRepodata["branch"] : '-') . '<br>' . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aRepodata["revision"]) . '<br>' . $this->_oHtml->getIconByType('comment') . t('commitmessage') . ':<br>' - ) - ."<pre>" . htmlentities($aRepodata["message"]). "</pre>"; + ) + . "<pre>" . htmlentities($aRepodata["message"]) . "</pre>"; } else { $sReturn .= $this->_oHtml->getBox("error", sprintf(t('class-project-error-no-repoinfo'), $aRepodata["error"])) - . $this->renderLink("setup") . '<br>'; + . $this->renderLink("setup") . '<br>'; } break; @@ -1491,36 +1533,40 @@ class projectgui extends project { $sReturn .= $this->_oHtml->getBox("error", sprintf(t('class-project-error-wrong-buildtype'), $this->_aPrjConfig["build"]["type"])); } if (array_key_exists("url", $this->_aPrjConfig["build"])) { - $sReturn.=t('repository-url') . ': ' . $this->_aPrjConfig["build"]["url"] . '<br>'; + $sReturn .= t('repository-url') . ': ' . $this->_aPrjConfig["build"]["url"] . '<br>'; } if (array_key_exists("webaccess", $this->_aPrjConfig["build"])) { - $sReturn.=t('repository-access-browser') . ':<br><a href="' . $this->_aPrjConfig["build"]["webaccess"] . '">' . $this->_aPrjConfig["build"]["webaccess"] . '</a><br>'; + $sReturn .= t('repository-access-browser') . ':<br><a href="' . $this->_aPrjConfig["build"]["webaccess"] . '">' . $this->_aPrjConfig["build"]["webaccess"] . '</a><br>'; } return $sReturn; } /** - * get html code for a link to the commit + * Get html code for a link to the commit * (works for guithub and gitlab instances) * - * @param string $sRevision + * @param null|string $sRevision * @return string */ - public function _renderRevision($sRevision) { + public function _renderRevision(null|string $sRevision): string + { $sUrl = str_replace('/tree/master', '', $this->_aPrjConfig["build"]["webaccess"]) . '/commit/' . $sRevision; return '<a href="' . $sUrl . '">' . $sRevision . '</a>'; - return $sUrl; + // return $sUrl; } + /** - * get html form with selectr for remote branches + * Get html form with selectr for remote branches + * * @param string $sActiveBranchname force active branch name * @param bool $bIgnoreCache flag to ignore exiting cached data * @return string */ - public function renderSelectRemoteBranches($sActiveBranchname = false, $bIgnoreCache=false) { - $this->log(__FUNCTION__."(sActiveBranchname = $sActiveBranchname, bIgnoreCache = ".($bIgnoreCache ? 'true' : 'false').") start"); - $aReturn = array(); - $aRadios = array(); + public function renderSelectRemoteBranches(string $sActiveBranchname = '', bool $bIgnoreCache = false): string + { + $this->log(__FUNCTION__ . "(sActiveBranchname = $sActiveBranchname, bIgnoreCache = " . ($bIgnoreCache ? 'true' : 'false') . ") start"); + $aReturn = []; + $aRadios = []; $bFoundActive = false; $i = 0; if (!$this->_oVcs) { @@ -1537,10 +1583,10 @@ class projectgui extends project { } foreach ($this->_oVcs->getRemoteBranches($bIgnoreCache) as $aBranch) { $sBranch = $aBranch['name']; - $aRadios[$sBranch] = array( + $aRadios[$sBranch] = [ 'value' => $sBranch, 'label' => $aBranch['label'], - ); + ]; // if no param was given the first branch will be marked if (!$sActiveBranchname) { $sActiveBranchname = $sBranch; @@ -1554,23 +1600,24 @@ class projectgui extends project { // not on the option (Chrome) // $aRadios[$sBranch]['onclick'] = 'document.getElementById(\'submitBranch\').click()'; } - }; + } + ; } // no branches were found if (count($aRadios) == 0) { return ''; } - $aForms = array( - 'frmSelectBranch' => array( - 'meta' => array( + $aForms = [ + 'frmSelectBranch' => [ + 'meta' => [ 'method' => 'POST', 'action' => '?', 'id' => 'frmSelectBranch', - ), - 'validate' => array(), - 'form' => array( - 'branchname' => array( + ], + 'validate' => [], + 'form' => [ + 'branchname' => [ 'inline' => true, 'type' => 'select', 'onchange' => 'document.getElementById(\'submitBranch\').click()', @@ -1578,33 +1625,34 @@ class projectgui extends project { 'label' => '<strong>' . t('branch-select') . '</strong>', 'validate' => 'isastring', 'options' => $aRadios, - ), - ), - ), - ); + ], + ], + ], + ]; // submit to switch branches - only if a selection is available if (count($aRadios) > 1 || !$bFoundActive) { - $aForms['frmSelectBranch']['form']['submitBranch'] = array( + $aForms['frmSelectBranch']['form']['submitBranch'] = [ 'type' => 'submit', 'name' => 'btnsave', 'onclick' => 'showModalMessage(\'' . t('branch-switch') . '\'); ', 'label' => t("change"), - 'value' => $this->_oHtml->getIcon('sign-ok').t("change"), - ); + 'value' => $this->_oHtml->getIcon('sign-ok') . t("change"), + ]; } $oFrm = new formgen($aForms); return $oFrm->renderHtml('frmSelectBranch') - . '<script>$("#submitBranch").hide();</script>'; + . '<script>$("#submitBranch").hide();</script>'; // return $oFrm->renderHtmlElement('dummy',$aFormData); } /** - * return html code for a list of all built packages and their usage + * Get html code for a list of all built packages and their usage * @return string */ - public function renderVersionUsage() { + public function renderVersionUsage(): string + { $sReturn = false; $sRowHead1 = false; $sRowHead2 = '<td></td>'; @@ -1615,26 +1663,26 @@ class projectgui extends project { } foreach ($this->getActivePhases() as $sPhase) { - $sRowHead1.='<th class="' . $sPhase . ' tdphase" colspan="' . (count($this->_aPlaces) + 1) . '">' . $sPhase . '</th>'; - $sRowHead2.='<td></td>' . $this->renderPlacesAsTd($sPhase); + $sRowHead1 .= '<th class="' . $sPhase . ' tdphase" colspan="' . (count($this->_aPlaces) + 1) . '">' . $sPhase . '</th>'; + $sRowHead2 .= '<td></td>' . $this->renderPlacesAsTd($sPhase); } - + krsort($aAllVersions); foreach ($aAllVersions as $sVersion => $aData) { - $sReturn.='<tr>'; - - $sInfos = $this->renderInfoLink($aData["info"], array('hpos' => 'left')); - $sReturn.='<td>' - . $this->_getChecksumDiv( - $aData['info']['revision'], - $this->_oHtml->getIconByType('calendar') . t('build-from') . ': ' . $sVersion .'<br>' - . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aData['info']["branch"] . '<br>' - . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aData['info']["revision"]) . '<br>' - ) - . '</td><td>' - . ' ' . $sInfos . ' ' - . '</td>' - ; + $sReturn .= '<tr>'; + + $sInfos = $this->renderInfoLink($aData["info"], ['hpos' => 'left']); + $sReturn .= '<td>' + . $this->_getChecksumDiv( + $aData['info']['revision'], + $this->_oHtml->getIconByType('calendar') . t('build-from') . ': ' . $sVersion . '<br>' + . $this->_oHtml->getIconByType('branch') . t('branch') . ': ' . $aData['info']["branch"] . '<br>' + . $this->_oHtml->getIconByType('revision') . t('revision') . ': ' . $this->_renderRevision($aData['info']["revision"]) . '<br>' + ) + . '</td><td>' + . ' ' . $sInfos . ' ' + . '</td>' + ; foreach ($this->getActivePhases() as $sPhase) { $sTLine = ''; @@ -1642,51 +1690,52 @@ class projectgui extends project { // $sReturn.=$aData["rollback"][$sPhase] ? '<td>'.$this->renderLink("rollback", $sPhase, $sVersion).'</td>' : '<td>Rollback NOT possible</td>'; // $sReturn.=$aData["rollback"][$sPhase] ? '<td> Y </td>' : '<td> N </td>'; - $sReturn.='<td> </td>'; + $sReturn .= '<td> </td>'; foreach (array_keys($this->_aPlaces) as $sPlace) { $bFound = false; - $sReturn.=$aData["usage"][$sPhase][$sPlace] - ? '<td class="' . $sPhase . '" style="text-align: center;">' - . $this->_getChecksumDiv($aData['info']['revision'], 'X') - . '</td>' - : '<td> </td>' - ; + $sReturn .= $aData["usage"][$sPhase][$sPlace] + ? '<td class="' . $sPhase . '" style="text-align: center;">' + . $this->_getChecksumDiv($aData['info']['revision'], 'X') + . '</td>' + : '<td> </td>' + ; } } - $sReturn.='</tr>'; + $sReturn .= '</tr>'; } $sReturn = t('class-project-info-table-packages') . '<br><br>' - . '<table>' - . '<thead><tr><td>Version</td><td></td>' - . $sRowHead1 - . '</tr><tr><td>' - . $sRowHead2 - . '</tr></thead>' - . '<tbody>' - . $sReturn - . '</tbody>' - . '</table>'; + . '<table>' + . '<thead><tr><td>Version</td><td></td>' + . $sRowHead1 + . '</tr><tr><td>' + . $sRowHead2 + . '</tr></thead>' + . '<tbody>' + . $sReturn + . '</tbody>' + . '</table>'; return $sReturn; } /** - * render graphical overview of process (in project overview) + * Get html code for graphical overview of process (in project overview) * @return string */ - public function renderVisual() { + public function renderVisual(): string + { $sReturn = ''; - $renderAdminLTE=new renderadminlte(); + $renderAdminLTE = new renderadminlte(); $sBarHeightBg = '1.0em'; $sBarHeight = '0.8em'; $sContinue = '<span style="font-size: 300%; color:#ace;">»»</span><br>'; - $aBranches=$this->getRemoteBranches(); - if(!is_array($aBranches)){ - return '<br>'.$this->_oHtml->getBox("error", t("project-setup-incomplete")); + $aBranches = $this->getRemoteBranches(); + if (!is_array($aBranches)) { + return '<br>' . $this->_oHtml->getBox("error", t("project-setup-incomplete")); } $sRepoBar = ''; @@ -1704,8 +1753,8 @@ class projectgui extends project { $sPackagebar = ''; $aVersions = $this->_getVersionUsage(); foreach ($aVersions as $sVersion => $aData) { - $sBar = $aData["info"]["revision"] ? $this->_getChecksumDiv($aData["info"]["revision"], '' , $sBarHeight) : ''; - $sPackagebar.='<span title="' . $sVersion . '" style="float: left; background:#eee; height: '.$sBarHeightBg.'; width:' . (100 / count($aVersions)) . '%">' . $sBar . ' </span>'; + $sBar = $aData["info"]["revision"] ? $this->_getChecksumDiv($aData["info"]["revision"], '', $sBarHeight) : ''; + $sPackagebar .= '<span title="' . $sVersion . '" style="float: left; background:#eee; height: ' . $sBarHeightBg . '; width:' . (100 / count($aVersions)) . '%">' . $sBar . ' </span>'; } $sPhaseImg = ''; @@ -1716,18 +1765,18 @@ class projectgui extends project { if ($this->canAcceptPhase($sLastPhase)) { $sAction .= $this->renderLink("accept", $sLastPhase); } - $sPhaseImg.='<div class="action">' . $sAction . '</div>'; + $sPhaseImg .= '<div class="action">' . $sAction . '</div>'; } $sLastPhase = $sPhase; $sFullbar = ''; foreach (array_keys($this->_aPlaces) as $sPlace) { - $sFullbar.='<span title="' . $this->_aPlaces[$sPlace] . '" style="float: left; background:#eee; height: '.$sBarHeightBg.'; width:' . (100 / count($this->_aPlaces)) . '%">' . $this->_renderBar($sPhase, $sPlace, $sBarHeight) . ' </span>'; + $sFullbar .= '<span title="' . $this->_aPlaces[$sPlace] . '" style="float: left; background:#eee; height: ' . $sBarHeightBg . '; width:' . (100 / count($this->_aPlaces)) . '%">' . $this->_renderBar($sPhase, $sPlace, $sBarHeight) . ' </span>'; } // $sDetail = $sFullbar . '<br><a href="#h3phases" class="scroll-link">' . $sPhase . '</a>'; $sDetail = $sFullbar . '<br>' . $sPhase; - $sPhaseImg.=' + $sPhaseImg .= ' <div class="process"> <div class="details">' . $sDetail . ' </div> </div>'; @@ -1738,55 +1787,61 @@ class projectgui extends project { . $renderAdminLTE->addRow( '' . $renderAdminLTE->addCol( - $renderAdminLTE->getCard([ - 'type'=>'', - 'variant'=>'outline', - 'title'=>'', - 'text'=> '<h3>'.t("versioncontrol"). '</h3>' . $sRepoBar . '<br> + $renderAdminLTE->getCard( + [ + 'type' => '', + 'variant' => 'outline', + 'title' => '', + 'text' => '<h3>' . t("versioncontrol") . '</h3>' . $sRepoBar . '<br> ' . t("repositoryinfos") . '<br> ' // . $this->_aPrjConfig["build"]["type"] - . preg_replace('/.*\@(.*):.*/', '$1', $this->_aPrjConfig["build"]["url"]) - . '<br>(<strong title="' . t('branch-select') . '">' . count($aBranches) . '</strong>)', + . preg_replace('/.*\@(.*):.*/', '$1', $this->_aPrjConfig["build"]["url"]) + . '<br>(<strong title="' . t('branch-select') . '">' . count($aBranches) . '</strong>)', ] - ), 2 - ) + ), + 2 + ) . $renderAdminLTE->addCol( '<div class="action">' . $sContinue . t("build-hint-overview") . '<br><br>' . ($this->canAcceptPhase() ? $this->renderLink("build") : '') . '</div>', 1 ) . $renderAdminLTE->addCol( - $renderAdminLTE->getCard([ - 'type'=>'', - 'variant'=>'outline', - 'title'=>'', - 'text'=> '<h3>'.$this->_oHtml->getIcon('package') . t("archive"). '</h3>' - . '<div class="archive">' + $renderAdminLTE->getCard( + [ + 'type' => '', + 'variant' => 'outline', + 'title' => '', + 'text' => '<h3>' . $this->_oHtml->getIcon('package') . t("archive") . '</h3>' + . '<div class="archive">' . '<div class="details">' - . $sPackagebar . '<br>' + . $sPackagebar . '<br>' . '</div>' . t("packages") . '<br>' - .'(<strong>' . count($this->_getVersionUsage()) . '</strong>)' - . '</div>' + . '(<strong>' . count($this->_getVersionUsage()) . '</strong>)' + . '</div>' ] - ), 2 - ) + ), + 2 + ) . $renderAdminLTE->addCol( - '<div class="action">'.$sContinue . sprintf(t("queue-hint-overview"), $this->getNextPhase()).'</div>', + '<div class="action">' . $sContinue . sprintf(t("queue-hint-overview"), $this->getNextPhase()) . '</div>', 1 ) . $renderAdminLTE->addCol( - $renderAdminLTE->getCard([ - 'type'=>'', - 'variant'=>'outline', - 'title'=>'', - 'text'=> '<h3>'.$this->_oHtml->getIcon('phase') . t("phases"). '</h3>' - . ($sPhaseImg ? $sPhaseImg : '<div class="process">' . t("none") . '</div>') + $renderAdminLTE->getCard( + [ + 'type' => '', + 'variant' => 'outline', + 'title' => '', + 'text' => '<h3>' . $this->_oHtml->getIcon('phase') . t("phases") . '</h3>' + . ($sPhaseImg ? $sPhaseImg : '<div class="process">' . t("none") . '</div>') ] - ), 6 - ) + ), + 6 ) - .'</div>' - ; + ) + . '</div>' + ; return $sReturn; } diff --git a/public_html/deployment/classes/user.class.php b/public_html/deployment/classes/user.class.php index 187bbdd52dfb1ec106fabf8f34d0270ae6f08753..ad58ef39a312697d1e3bd937ae190c991cd6bd2b 100644 --- a/public_html/deployment/classes/user.class.php +++ b/public_html/deployment/classes/user.class.php @@ -208,7 +208,7 @@ class user { /** * return html code to display a denied message - * @return type + * @return string */ public function showDenied(){ return '<div class="alert alert-danger" role="alert">'