assign('FORM_1_PLACE_HOLDER', $form1); $ss->assign('form_action', $form_action); $ss->assign('hidden_fields', $hidden_fields); $result = PackageManagerDisplay::getHeader(); $header_text = $result['text']; $isAlive = $result['isAlive']; $show_login = $result['show_login']; $mi_errors = ModuleInstaller::getErrors(); $error_html = ""; if(!empty($mi_errors)){ $error_html = ""; foreach($mi_errors as $error){ $error_html .= "".$error."
"; } $error_html .= "
"; } $form2 = ""; $form2 .= $error_html; if(!$isAlive) $form2 .= ""; $form2 .= "
".$header_text."
"; $tree = null; //if($isAlive){ $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive); $tree->tree_style= 'include/ytree/TreeView/css/check/tree.css'; $ss->assign('TREEHEADER',$tree->generate_header()); //} //$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings); $form2 .= ""; $form2 .= "
"; if($isAlive){ $form2 .= ""; }else{ $form2 .= ""; } $form2 .= ""; if($isAlive){ $form2 .= " Collapse"; }else{ $form2 .= ""; } $form2 .= "
"; $form2 = ''; //Commenting out the form as part of sugar depot hiding. $ss->assign('installation', ($install ? 'true' : 'false')); $mod_strings = return_module_language($current_language, "Administration"); $ss->assign('MOD', $mod_strings); $ss->assign('module_load', 'true'); $ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install)); $show_login = false; //hiding install from sugar $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login)); $ss->assign('FORM_2_PLACE_HOLDER', $form2); $ss->assign('MOD', $mod_strings); $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED']; $ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types)); $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl'); return $str; } /** * A Static method to Build the display for the package manager * * @param String form1 - the form to display for manual downloading * @param String hidden_fields - the hidden fields related to downloading a package * @param String form_action - the form_action to be used when downloading from the server * @param String types - the types of objects we will request from the server * @param String active_form - the form to display first * @return String - a string of html which will be used to display the forms */ function buildPatchDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1'){ global $current_language; $mod_strings = return_module_language($current_language, "Administration"); $ss = new Sugar_Smarty(); $ss->assign('FORM_1_PLACE_HOLDER', $form1); $ss->assign('form_action', $form_action); $ss->assign('hidden_fields', $hidden_fields); $mod_strings = return_module_language($current_language, "Administration"); $ss->assign('MOD', $mod_strings); $result = PackageManagerDisplay::getHeader(); $header_text = $result['text']; $isAlive = $result['isAlive']; $show_login = $result['show_login']; $display = 'none'; //if($isAlive){ $display = 'block'; //} $form2 = ""; if(!$isAlive) $form2 .= ""; $form2 .= "
".$header_text."
"; $form2 .= "
"; if($show_login){ $form2 .= ""; } $form2 .= "
"; $loginViewStyle = ($isAlive ? 'none' : 'block'); $selectViewStyle = ($isAlive ? 'block' : 'none'); $form2 .= "
"; $form2 .= "
"; $form2 .= "
"; if(!$show_login) $loginViewStyle = 'none'; //$form2 .= "
"; //$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings, $isAlive); //$form2 .= "
"; $form2 .= "
"; $form2 = ''; $packages = array(); $releases = array(); if($isAlive){ $filter = array(); $count = count($types); $index = 1; $type_str = '"'; foreach($types as $type){ $type_str .= "'".$type."'"; if($index < $count) $type_str .= ","; $index++; } $type_str .= '"'; $filter = array('type' => $type_str); $filter = PackageManager::toNameValueList($filter); $pm = new PackageManager(); /*if(in_array('patch', $types)){ $releases = $pm->getReleases('3', '3', $filter); }else{ $releases = $pm->getReleases('', '', $filter); }*/ } if($form_action == 'install.php' && (empty($releases) || count($releases['packages']) == 0)){ //return false; } $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive); $tree->tree_style= 'include/ytree/TreeView/css/check/tree.css'; $ss->assign('TREEHEADER',$tree->generate_header()); $ss->assign('module_load', 'false'); $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login)); $ss->assign('FORM_2_PLACE_HOLDER', $form2); $ss->assign('scripts', PackageManagerDisplay::getDisplayScript(false, 'patch', $releases, $types, $isAlive)); $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl'); return $str; } function buildInstalledGrid($mod_strings, $types = array('modules')){ $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED']; $output = ''; $output .= '
'.$descItemsInstalled.'
'; $output .= "
"; return $output; } function buildLoginPanel($mod_strings, $display_cancel){ $credentials = PackageManager::getCredentials(); $output = "
".$mod_strings['HDR_LOGIN_PANEL']."
"; $output .= "
"; $output .= ""; $terms = PackageManager::getTermsAndConditions(); $output .= "'; $_SESSION['SugarDepot_TermsVersion'] = (!empty($terms['version']) ? $terms['version'] : ''); $output .= ""; $output .= ""; $output .= ""; $output .= "
".$mod_strings['LBL_USERNAME']."".$mod_strings['LNK_NEW_ACCOUNT']."
".$mod_strings['LBL_PASSWORD']."".$mod_strings['LNK_FORGOT_PASS']."
".$mod_strings['LBL_TERMS_AND_CONDITIONS']."
".$mod_strings['LBL_ACCEPT_TERMS']."
"; $output .= ""; if($display_cancel){ $output .= " "; } $output .= "
"; $output .= "
"; return $output; } /** * Build html in order to display the grids relevant for module loader * * @param Tree tree - the tree which we are using to display the categories * @param Array mod_strings - the local mod strings to display * @return String - a string of html */ function buildGridOutput($tree, $mod_strings, $display = true, $show_login = true){ $output = "
"; $loginViewStyle = ($display ? 'none' : 'block'); $selectViewStyle = ($display ? 'block' : 'none'); $output .= "
"; //if($display){ $output .= ""; $output .= ""; $output .= "
"; $output .= "
"; $output .= $tree->generate_nodes_array(); $output .= "
"; $output .= "
"; $output .= "
"; $output .= "
"; $output .= ""; $output .= "
"; // } $output .= "
"; if(!$show_login) $loginViewStyle = 'none'; // $output .= "
"; // jchi ,#24296 :commented code because we are currently not using depot, in the future this may change so you can put this code back in. //$output .= PackageManagerDisplay::buildLoginPanel($mod_strings, $display); //$output .= "
"; //$output .= "
"; $output .= "
"; return $output; } /** * A Static method used to build the initial treeview when the page is first displayed * * @param String div_id - this div in which to display the tree * @return Tree - the tree that is built */ function buildTreeView($div_id, $isAlive = true){ $tree = new Tree($div_id); $nodes = array(); if($isAlive) $nodes = PackageManager::getCategories(''); foreach($nodes as $arr_node){ $node = new Node($arr_node['id'], $arr_node['label']); $node->dynamicloadfunction = 'PackageManager.loadDataForNodeForPackage'; $node->expanded = false; $node->dynamic_load = true; $node->set_property('href',"javascript:PackageManager.catClick('treeview');"); $tree->add_node($node); $node->set_property('description', $arr_node['description']); } return $tree; } /** * A Static method used to obtain the div for the license * * @param String license_file - the path to the license file * @param String form_action - the form action when accepting the license file * @param String next_step - the value for the next step in the installation process * @param String zipFile - a string representing the path to the zip file * @param String type - module/patch.... * @param String manifest - the path to the manifest file * @param String modify_field - the field to update when the radio button is changed * @return String - a form used to display the license */ function getLicenseDisplay($license_file, $form_action, $next_step, $zipFile, $type, $manifest, $modify_field){ global $current_language; $mod_strings = return_module_language($current_language, "Administration"); $contents = sugar_file_get_contents($license_file); $div_id = urlencode($zipFile); $display = "
"; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= "
"; $display .= "{$mod_strings['LBL_MODULE_LICENSE']}"; $display .= ""; $display .= " Expand
"; $display .= "
"; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= ""; $display .= "
"; $display .= ""; $display .= "
"; $display .= "{$mod_strings['LBL_ACCEPT']} "; $display .= "{$mod_strings['LBL_DENY']}"; $display .= "
"; $display .= "
"; $display .= "
"; return $display; } /** * A Static method used to generate the javascript for the page * * @return String - the javascript required for the page */ function getDisplayScript($install = false, $type = 'module', $releases = null, $types = array(), $isAlive = true){ global $sugar_version, $sugar_config; global $current_language; $mod_strings = return_module_language($current_language, "Administration"); $ss = new Sugar_Smarty(); $ss->assign('MOD', $mod_strings); if(!$install){ $install = 0; } $ss->assign('INSTALLATION', $install); $ss->assign('WAIT_IMAGE', SugarThemeRegistry::current()->getImage("loading","border='0' align='bottom'")); $ss->assign('sugar_version', $sugar_version); $ss->assign('js_custom_version', $sugar_config['js_custom_version']); $ss->assign('IS_ALIVE', $isAlive); //if($type == 'patch' && $releases != null){ if($type == 'patch'){ $ss->assign('module_load', 'false'); $patches = PackageManagerDisplay::createJavascriptPackageArray($releases); $ss->assign('PATCHES', $patches); $ss->assign('GRID_TYPE', implode(',', $types)); }else{ $pm = new PackageManager(); $releases = $pm->getPackagesInStaging(); $patches = PackageManagerDisplay::createJavascriptModuleArray($releases); $ss->assign('PATCHES', $patches); $installeds = $pm->getinstalledPackages(); $patches = PackageManagerDisplay::createJavascriptModuleArray($installeds, 'mti_installed_data'); $ss->assign('INSTALLED_MODULES', $patches); $ss->assign('UPGARDE_WIZARD_URL', 'index.php?module=UpgradeWizard&action=index'); $ss->assign('module_load', 'true'); } if(!empty($GLOBALS['ML_STATUS_MESSAGE'])) $ss->assign('ML_STATUS_MESSAGE',$GLOBALS['ML_STATUS_MESSAGE']); //Bug 24064. Checking and Defining labels since these might not be cached during Upgrade if(!isset($mod_strings['LBL_ML_INSTALL']) || empty($mod_strings['LBL_ML_INSTALL'])){ $mod_strings['LBL_ML_INSTALL'] = 'Install'; } if(!isset($mod_strings['LBL_ML_ENABLE_OR_DISABLE']) || empty($mod_strings['LBL_ML_ENABLE_OR_DISABLE'])) { $mod_strings['LBL_ML_ENABLE_OR_DISABLE'] = 'Enable/Disable'; } if(!isset($mod_strings['LBL_ML_DELETE'])|| empty($mod_strings['LBL_ML_DELETE'])){ $mod_strings['LBL_ML_DELETE'] = 'Delete'; } //Add by jchi 6/23/2008 to fix the bug 21667 $filegrid_column_ary = array( 'Name' => $mod_strings['LBL_ML_NAME'], 'Install' => $mod_strings['LBL_ML_INSTALL'], 'Delete' => $mod_strings['LBL_ML_DELETE'], 'Type' => $mod_strings['LBL_ML_TYPE'], 'Version' => $mod_strings['LBL_ML_VERSION'], 'Published' => $mod_strings['LBL_ML_PUBLISHED'], 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'], 'Description' => $mod_strings['LBL_ML_DESCRIPTION'] ); $filegridinstalled_column_ary = array( 'Name' => $mod_strings['LBL_ML_NAME'], 'Install' => $mod_strings['LBL_ML_INSTALL'], 'Action' => $mod_strings['LBL_ML_ACTION'], 'Enable_Or_Disable' => $mod_strings['LBL_ML_ENABLE_OR_DISABLE'], 'Type' => $mod_strings['LBL_ML_TYPE'], 'Version' => $mod_strings['LBL_ML_VERSION'], 'Date_Installed' => $mod_strings['LBL_ML_INSTALLED'], 'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'], 'Description' => $mod_strings['LBL_ML_DESCRIPTION'] ); $ss->assign('ML_FILEGRID_COLUMN',$filegrid_column_ary); $ss->assign('ML_FILEGRIDINSTALLED_COLUMN',$filegridinstalled_column_ary); //end $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageManagerScripts.tpl'); return $str; } function createJavascriptPackageArray($releases){ $output = "var mti_data = ["; $count = count($releases); $index = 1; if(!empty($releases['packages'])){ foreach($releases['packages'] as $release){ $release = PackageManager::fromNameValueList($release); $output .= "["; $output .= "'".$release['description']."', '".$release['version']."', '".$release['build_number']."', '".$release['id']."'"; $output .= "]"; if($index < $count) $output .= ","; $index++; } } $output .= "]\n;"; return $output; } function createJavascriptModuleArray($modules, $variable_name = 'mti_data'){ $output = "var ".$variable_name." = ["; $count = count($modules); $index = 1; if(!empty($modules)){ foreach($modules as $module){ $output .= "["; $output .= "'".$module['name']."', '".$module['file_install']."', '".$module['file']."', '"; if(!empty($module['enabled'])) $output .= $module['enabled'].'_'.$module['file']."', '"; $description = js_escape($module['description']); $output .= $module['type']."', '".$module['version']."', '".$module['published_date']."', '".$module['uninstallable']."', '".$description."'".(isset($module['upload_file'])?" , '".$module['upload_file']."']":"]"); if($index < $count) $output .= ","; $index++; } } $output .= "]\n;"; return $output; } /** * This method is meant to be used to display the license agreement inline on the page * if the system would like to perform the installation on the same page via an Ajax call */ function buildLicenseOutput($file){ global $current_language; $mod_strings = return_module_language($current_language, "Administration"); $contents = ''; $pm = new PackageManager(); $contents = $pm->getLicenseFromFile($file); $ss = new Sugar_Smarty(); $ss->assign('MOD', $mod_strings); $ss->assign('LICENSE_CONTENTS', $contents); $ss->assign('FILE', $file); $str = $ss->fetch('ModuleInstall/PackageManagerLicense.tpl'); $GLOBALS['log']->debug('LICENSE OUTPUT: '.$str); return $str; } function getHeader(){ global $current_language; $mod_strings = return_module_language($current_language, "Administration"); $header_text = ''; $isAlive = false; $show_login = false; if(!function_exists('curl_init') && $show_login){ $header_text = "".$mod_strings['ERR_ENABLE_CURL'].""; $show_login = false; }else{ $credentials = PackageManager::getCredentials(); if(empty($credentials['username']) || empty($credentials['password'])){ //$header_text = "".$mod_strings['ERR_CREDENTIALS_MISSING'].""; } else{ $result = PackageManagerComm::login(); if((is_array($result) && !empty($result['faultcode'])) || $result == false){ $header_text = "".$result['faultstring'].""; }else{ $header_text = PackageManager::getPromotion(); $isAlive = true; } } } return array('text' => $header_text, 'isAlive' => $isAlive, 'show_login' => $show_login); } function buildInstallGrid($view){ $uh = new UpgradeHistory(); $installeds = $uh->getAll(); $upgrades_installed = 0; $installed_objects = array(); foreach($installeds as $installed) { $filename = from_html($installed->filename); $date_entered = $installed->date_entered; $type = $installed->type; $version = $installed->version; $upgrades_installed++; $link = ""; switch($type) { case "theme": case "langpack": case "module": case "patch": $manifest_file = extractManifest($filename); require_once($manifest_file); $name = empty($manifest['name']) ? $filename : $manifest['name']; $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description']; if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed)) && is_file($filename) && !empty($manifest['is_uninstallable'])) { $link = urlencode( $filename ); } else { $link = 'false'; } break; default: break; } if($view == 'default' && $type != 'patch') { continue; } if($view == 'module' && $type != 'module' && $type != 'theme' && $type != 'langpack') { continue; } $target_manifest = remove_file_extension( $filename ) . "-manifest.php"; require_once( "$target_manifest" ); if(isset($manifest['icon']) && $manifest['icon'] != "") { $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : ""; $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : ""; $manifest_icon = clean_path($manifest['icon']); $icon = ""; } else { $icon = getImageForType( $manifest['type'] ); } $installed_objects[] = array('icon' => $icon, 'name' => $name, 'type' => $type, 'version' => $version, 'date_entered' => $date_entered, 'description' => $description, 'file' => $link); //print( "
\n" ); //print( "$icon$name$type$version$date_entered$description$link\n" ); //print( "
\n" ); } } } ?>