protected function GetMaxUpload() { $iMaxUpload = ini_get('upload_max_filesize'); if (!$iMaxUpload) { $sRet = Dict::S('Attachments:UploadNotAllowedOnThisSystem'); } else { $iMaxUpload = utils::ConvertToBytes($iMaxUpload); if ($iMaxUpload > 1024 * 1024 * 1024) { $sRet = Dict::Format('Attachment:Max_Go', sprintf('%0.2f', $iMaxUpload / (1024 * 1024 * 1024))); } else { if ($iMaxUpload > 1024 * 1024) { $sRet = Dict::Format('Attachment:Max_Mo', sprintf('%0.2f', $iMaxUpload / (1024 * 1024))); } else { $sRet = Dict::Format('Attachment:Max_Ko', sprintf('%0.2f', $iMaxUpload / 1024)); } } } return $sRet; }
function SetMemoryLimit($oP) { $sMemoryLimit = trim(ini_get('memory_limit')); if (empty($sMemoryLimit)) { // On some PHP installations, memory_limit does not exist as a PHP setting! // (encountered on a 5.2.0 under Windows) // In that case, ini_set will not work, let's keep track of this and proceed with the data load $oP->p("No memory limit has been defined in this instance of PHP"); } else { // Check that the limit will allow us to load the data // $iMemoryLimit = utils::ConvertToBytes($sMemoryLimit); if ($iMemoryLimit < SAFE_MINIMUM_MEMORY) { if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE) { $oP->p("memory_limit is too small: {$iMemoryLimit} and can not be increased by the script itself."); } else { $oP->p("memory_limit increased from {$iMemoryLimit} to " . SAFE_MINIMUM_MEMORY . "."); } } } }
public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array()) { static $iInputId = 0; $sFieldPrefix = ''; $sFormPrefix = isset($aArgs['formPrefix']) ? $aArgs['formPrefix'] : ''; $sFieldPrefix = isset($aArgs['prefix']) ? $sFormPrefix . $aArgs['prefix'] : $sFormPrefix; if ($sDisplayValue == '') { $sDisplayValue = $value; } if (isset($aArgs[$sAttCode]) && empty($value)) { // default value passed by the context (either the app context of the operation) $value = $aArgs[$sAttCode]; } if (!empty($iId)) { $iInputId = $iId; } else { $iInputId = $oPage->GetUniqueId(); } if (!$oAttDef->IsExternalField()) { $bMandatory = 'false'; if (!$oAttDef->IsNullAllowed() || $iFlags & OPT_ATT_MANDATORY) { $bMandatory = 'true'; } $sValidationField = "<span class=\"form_validation\" id=\"v_{$iId}\"></span>"; $sHelpText = htmlentities($oAttDef->GetHelpOnEdition(), ENT_QUOTES, 'UTF-8'); $aEventsList = array(); switch ($oAttDef->GetEditClass()) { case 'Date': $aEventsList[] = 'validate'; $aEventsList[] = 'keyup'; $aEventsList[] = 'change'; if ($iFlags & OPT_ATT_MANDATORY && empty($sDisplayValue)) { $sDisplayValue = date($oAttDef->GetDateFormat()); } $sHTMLValue = "<input title=\"{$sHelpText}\" class=\"date-pick\" type=\"text\" size=\"12\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"" . htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8') . "\" id=\"{$iId}\"/> {$sValidationField}"; break; case 'DateTime': $aEventsList[] = 'validate'; $aEventsList[] = 'keyup'; $aEventsList[] = 'change'; if ($iFlags & OPT_ATT_MANDATORY && empty($sDisplayValue)) { $sDisplayValue = date($oAttDef->GetDateFormat()); } $sHTMLValue = "<input title=\"{$sHelpText}\" class=\"datetime-pick\" type=\"text\" size=\"20\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"" . htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8') . "\" id=\"{$iId}\"/> {$sValidationField}"; break; case 'Duration': $aEventsList[] = 'validate'; $aEventsList[] = 'change'; $oPage->add_ready_script("\$('#{$iId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('{$iId}'); });"); $oPage->add_ready_script("\$('#{$iId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('{$iId}'); });"); $oPage->add_ready_script("\$('#{$iId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('{$iId}'); });"); $oPage->add_ready_script("\$('#{$iId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('{$iId}'); });"); $aVal = AttributeDuration::SplitDuration($value); $sDays = "<input title=\"{$sHelpText}\" type=\"text\" style=\"text-align:right\" size=\"3\" name=\"attr_{$sFieldPrefix}{$sAttCode}[d]{$sNameSuffix}\" value=\"{$aVal['days']}\" id=\"{$iId}_d\"/>"; $sHours = "<input title=\"{$sHelpText}\" type=\"text\" style=\"text-align:right\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[h]{$sNameSuffix}\" value=\"{$aVal['hours']}\" id=\"{$iId}_h\"/>"; $sMinutes = "<input title=\"{$sHelpText}\" type=\"text\" style=\"text-align:right\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[m]{$sNameSuffix}\" value=\"{$aVal['minutes']}\" id=\"{$iId}_m\"/>"; $sSeconds = "<input title=\"{$sHelpText}\" type=\"text\" style=\"text-align:right\" size=\"2\" name=\"attr_{$sFieldPrefix}{$sAttCode}[s]{$sNameSuffix}\" value=\"{$aVal['seconds']}\" id=\"{$iId}_s\"/>"; $sHidden = "<input type=\"hidden\" id=\"{$iId}\" value=\"" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "\"/>"; $sHTMLValue = Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds) . $sHidden . " " . $sValidationField; $oPage->add_ready_script("\$('#{$iId}').bind('update', function(evt, sFormId) { return ToggleDurationField('{$iId}'); });"); break; case 'Password': $aEventsList[] = 'validate'; $aEventsList[] = 'keyup'; $aEventsList[] = 'change'; $sHTMLValue = "<input title=\"{$sHelpText}\" type=\"password\" size=\"30\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "\" id=\"{$iId}\"/> {$sValidationField}"; break; case 'OQLExpression': case 'Text': $aEventsList[] = 'validate'; $aEventsList[] = 'keyup'; $aEventsList[] = 'change'; $sEditValue = $oAttDef->GetEditValue($value); $aStyles = array(); $sStyle = ''; $sWidth = $oAttDef->GetWidth('width', ''); if (!empty($sWidth)) { $aStyles[] = 'width:' . $sWidth; } $sHeight = $oAttDef->GetHeight('height', ''); if (!empty($sHeight)) { $aStyles[] = 'height:' . $sHeight; } if (count($aStyles) > 0) { $sStyle = 'style="' . implode('; ', $aStyles) . '"'; } if ($oAttDef->GetEditClass() == 'OQLExpression') { $sTestResId = 'query_res_' . $sFieldPrefix . $sAttCode . $sNameSuffix; //$oPage->GetUniqueId(); $sBaseUrl = utils::GetAbsoluteUrlAppRoot() . 'pages/run_query.php?expression='; $sInitialUrl = $sBaseUrl . urlencode($sEditValue); $sAdditionalStuff = "<a id=\"{$sTestResId}\" target=\"_blank\" href=\"{$sInitialUrl}\">" . Dict::S('UI:Edit:TestQuery') . "</a>"; $oPage->add_ready_script("\$('#{$iId}').bind('change keyup', function(evt, sFormId) { \$('#{$sTestResId}').attr('href', '{$sBaseUrl}'+encodeURIComponent(\$(this).val())); } );"); } else { $sAdditionalStuff = ""; } // Ok, the text area is drawn here $sHTMLValue = "<table><tr><td><textarea class=\"resizable\" title=\"{$sHelpText}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"{$iId}\" {$sStyle}>" . htmlentities($sEditValue, ENT_QUOTES, 'UTF-8') . "</textarea>{$sAdditionalStuff}</td><td>{$sValidationField}</td></tr></table>"; break; case 'CaseLog': $aStyles = array(); $sStyle = ''; $sWidth = $oAttDef->GetWidth('width', ''); if (!empty($sWidth)) { $aStyles[] = 'width:' . $sWidth; } $sHeight = $oAttDef->GetHeight('height', ''); if (!empty($sHeight)) { $aStyles[] = 'height:' . $sHeight; } if (count($aStyles) > 0) { $sStyle = 'style="' . implode('; ', $aStyles) . '"'; } $sHeader = '<div class="caselog_input_header"> ' . Dict::S('UI:CaseLogTypeYourTextHere') . '</div>'; $sEditValue = $oAttDef->GetEditValue($value); $sPreviousLog = is_object($value) ? $value->GetAsHTML($oPage, true, array('AttributeText', 'RenderWikiHtml')) : ''; $iEntriesCount = is_object($value) ? count($value->GetIndex()) : 0; $sHidden = "<input type=\"hidden\" id=\"{$iId}_count\" value=\"{$iEntriesCount}\"/>"; // To know how many entries the case log already contains $sHTMLValue = "<div class=\"caselog\" {$sStyle}><table style=\"width:100%;\"><tr><td>{$sHeader}<textarea style=\"border:0;width:100%\" title=\"{$sHelpText}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"{$iId}\">" . htmlentities($sEditValue, ENT_QUOTES, 'UTF-8') . "</textarea>{$sPreviousLog}</td><td>{$sValidationField}</td></tr></table>{$sHidden}</div>"; $oPage->add_ready_script("\$('#{$iId}').bind('keyup change validate', function(evt, sFormId) { return ValidateCaseLogField('{$iId}', {$bMandatory}, sFormId) } );"); // Custom validation function break; case 'HTML': $oWidget = new UIHTMLEditorWidget($iId, $oAttDef, $sNameSuffix, $sFieldPrefix, $sHelpText, $sValidationField, $value, $bMandatory); $sHTMLValue = $oWidget->Display($oPage, $aArgs); break; case 'LinkedSet': if ($oAttDef->IsIndirect()) { $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix, $oAttDef->DuplicatesAllowed(), $aArgs); } else { $oWidget = new UILinksWidgetDirect($sClass, $sAttCode, $iId, $sNameSuffix, $aArgs); } $aEventsList[] = 'validate'; $aEventsList[] = 'change'; $oObj = isset($aArgs['this']) ? $aArgs['this'] : null; $sHTMLValue = $oWidget->Display($oPage, $value, array(), $sFormPrefix, $oObj); break; case 'Document': $aEventsList[] = 'validate'; $aEventsList[] = 'change'; $oDocument = $value; // Value is an ormDocument object $sFileName = ''; if (is_object($oDocument)) { $sFileName = $oDocument->GetFileName(); } $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); $sHTMLValue = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$iMaxFileSize}\" />\n"; $sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}[filename]\" type=\"hidden\" id=\"{$iId}\" \" value=\"" . htmlentities($sFileName, ENT_QUOTES, 'UTF-8') . "\"/>\n"; $sHTMLValue .= "<span id=\"name_{$iInputId}\">{$sFileName}</span><br/>\n"; $sHTMLValue .= "<input title=\"{$sHelpText}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}[fcontents]\" type=\"file\" id=\"file_{$iId}\" onChange=\"UpdateFileName('{$iId}', this.value)\"/> {$sValidationField}\n"; break; case 'StopWatch': $sHTMLValue = "The edition of a stopwatch is not allowed!!!"; break; case 'List': // Not editable for now... $sHTMLValue = ''; break; case 'One Way Password': $aEventsList[] = 'validate'; $oWidget = new UIPasswordWidget($sAttCode, $iId, $sNameSuffix); $sHTMLValue = $oWidget->Display($oPage, $aArgs); // Event list & validation is handled directly by the widget break; case 'ExtKey': $aEventsList[] = 'validate'; $aEventsList[] = 'change'; $oAllowedValues = MetaModel::GetAllowedValuesAsObjectSet($sClass, $sAttCode, $aArgs); $sFieldName = $sFieldPrefix . $sAttCode . $sNameSuffix; $aExtKeyParams = $aArgs; $aExtKeyParams['iFieldSize'] = $oAttDef->GetMaxSize(); $aExtKeyParams['iMinChars'] = $oAttDef->GetMinAutoCompleteChars(); $sHTMLValue = UIExtKeyWidget::DisplayFromAttCode($oPage, $sAttCode, $sClass, $oAttDef->GetLabel(), $oAllowedValues, $value, $iId, $bMandatory, $sFieldName, $sFormPrefix, $aExtKeyParams); $sHTMLValue .= "<!-- iFlags: {$iFlags} bMandatory: {$bMandatory} -->\n"; break; case 'RedundancySetting': $sHTMLValue = '<table>'; $sHTMLValue .= '<tr>'; $sHTMLValue .= '<td>'; $sHTMLValue .= '<div id="' . $iId . '">'; $sHTMLValue .= $oAttDef->GetDisplayForm($value, $oPage, true); $sHTMLValue .= '</div>'; $sHTMLValue .= '</td>'; $sHTMLValue .= '<td>' . $sValidationField . '</td>'; $sHTMLValue .= '</tr>'; $sHTMLValue .= '</table>'; $oPage->add_ready_script("\$('#{$iId} :input').bind('keyup change validate', function(evt, sFormId) { return ValidateRedundancySettings('{$iId}',sFormId); } );"); // Custom validation function break; case 'String': default: $aEventsList[] = 'validate'; // #@# todo - add context information (depending on dimensions) $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs); $iFieldSize = $oAttDef->GetMaxSize(); if ($aAllowedValues !== null) { // Discrete list of values, use a SELECT or RADIO buttons depending on the config $sDisplayStyle = $oAttDef->GetDisplayStyle(); switch ($sDisplayStyle) { case 'radio': case 'radio_horizontal': case 'radio_vertical': $sHTMLValue = ''; $bVertical = $sDisplayStyle != 'radio_horizontal'; $sHTMLValue = $oPage->GetRadioButtons($aAllowedValues, $value, $iId, "attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}", $bMandatory, $bVertical, $sValidationField); $aEventsList[] = 'change'; break; case 'select': default: $sHTMLValue = "<select title=\"{$sHelpText}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"{$iId}\">\n"; $sHTMLValue .= "<option value=\"\">" . Dict::S('UI:SelectOne') . "</option>\n"; foreach ($aAllowedValues as $key => $display_value) { if (count($aAllowedValues) == 1 && $bMandatory == 'true') { // When there is only once choice, select it by default $sSelected = ' selected'; } else { $sSelected = $value == $key ? ' selected' : ''; } $sHTMLValue .= "<option value=\"{$key}\"{$sSelected}>{$display_value}</option>\n"; } $sHTMLValue .= "</select> {$sValidationField}\n"; $aEventsList[] = 'change'; } } else { $sHTMLValue = "<input title=\"{$sHelpText}\" type=\"text\" size=\"30\" maxlength=\"{$iFieldSize}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"" . htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8') . "\" id=\"{$iId}\"/> {$sValidationField}"; $aEventsList[] = 'keyup'; $aEventsList[] = 'change'; } break; } $sPattern = addslashes($oAttDef->GetValidationPattern()); //'^([0-9]+)$'; if (!empty($aEventsList)) { $sNullValue = $oAttDef->GetNullValue(); if (!is_numeric($sNullValue)) { $sNullValue = "'{$sNullValue}'"; // Add quotes to turn this into a JS string if it's not a number } $sOriginalValue = $iFlags & OPT_ATT_MUSTCHANGE ? json_encode($value) : 'undefined'; $oPage->add_ready_script("\$('#{$iId}').bind('" . implode(' ', $aEventsList) . "', function(evt, sFormId) { return ValidateField('{$iId}', '{$sPattern}', {$bMandatory}, sFormId, {$sNullValue}, {$sOriginalValue}) } );\n"); // Bind to a custom event: validate } $aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one if (count($aDependencies) > 0) { // Unbind first to avoid duplicate event handlers in case of reload of the whole (or part of the) form $oPage->add_ready_script("\$('#{$iId}').unbind('change.dependencies').bind('change.dependencies', function(evt, sFormId) { return oWizardHelper{$sFormPrefix}.UpdateDependentFields(['" . implode("','", $aDependencies) . "']) } );\n"); // Bind to a custom event: validate } } $oPage->add_dict_entry('UI:ValueMustBeSet'); $oPage->add_dict_entry('UI:ValueMustBeChanged'); $oPage->add_dict_entry('UI:ValueInvalidFormat'); return "<div>{$sHTMLValue}</div>"; }
/** * Helper function check the connection to the database, verify a few conditions (minimum version, etc...) and (if connected) * enumerate the existing databases (if possible) * @return mixed false if the connection failed or array('checks' => Array of CheckResult, 'databases' => Array of database names (as strings) or null if not allowed) */ static function CheckServerConnection($sDBServer, $sDBUser, $sDBPwd) { $aResult = array('checks' => array(), 'databases' => null); try { $oDBSource = new CMDBSource(); $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd); $aResult['checks'][] = new CheckResult(CheckResult::INFO, "Connection to '{$sDBServer}' as '{$sDBUser}' successful."); $aResult['checks'][] = new CheckResult(CheckResult::INFO, "Info - User privileges: " . $oDBSource->GetRawPrivileges()); $sDBVersion = $oDBSource->GetDBVersion(); if (version_compare($sDBVersion, self::MYSQL_MIN_VERSION, '>=')) { $aResult['checks'][] = new CheckResult(CheckResult::INFO, "Current MySQL version ({$sDBVersion}), greater than minimum required version (" . self::MYSQL_MIN_VERSION . ")"); // Check some server variables $iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet'); $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); if ($iMaxAllowedPacket >= 500 + $iMaxUploadSize) { $aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_allowed_packet ({$iMaxAllowedPacket}) is big enough compared to upload_max_filesize ({$iMaxUploadSize})."); } else { if ($iMaxAllowedPacket < $iMaxUploadSize) { $aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_allowed_packet ({$iMaxAllowedPacket}) is not big enough. Please, consider setting it to at least " . (500 + $iMaxUploadSize) . "."); } } $iMaxConnections = $oDBSource->GetServerVariable('max_connections'); if ($iMaxConnections < 5) { $aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_connections ({$iMaxConnections}) is not enough. Please, consider setting it to at least 5."); } else { $aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_connections is set to {$iMaxConnections}."); } } else { $aResult['checks'][] = new CheckResult(CheckResult::ERROR, "Error: Current MySQL version is ({$sDBVersion}), minimum required version (" . self::MYSQL_MIN_VERSION . ")"); } try { $aResult['databases'] = $oDBSource->ListDB(); } catch (Exception $e) { $aResult['databases'] = null; } } catch (Exception $e) { return false; } return $aResult; }
*/ define('SAFE_MINIMUM_MEMORY', 64 * 1024 * 1024); require_once '../approot.inc.php'; require_once APPROOT . '/application/utils.inc.php'; require_once APPROOT . '/setup/setuppage.class.inc.php'; require_once APPROOT . '/setup/moduleinstaller.class.inc.php'; $sMemoryLimit = trim(ini_get('memory_limit')); if (empty($sMemoryLimit)) { // On some PHP installations, memory_limit does not exist as a PHP setting! // (encountered on a 5.2.0 under Windows) // In that case, ini_set will not work, let's keep track of this and proceed with the data load SetupPage::log_info("No memory limit has been defined in this instance of PHP"); } else { // Check that the limit will allow us to load the data // $iMemoryLimit = utils::ConvertToBytes($sMemoryLimit); if ($iMemoryLimit < SAFE_MINIMUM_MEMORY) { if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE) { SetupPage::log_error("memory_limit is too small: {$iMemoryLimit} and can not be increased by the script itself."); } else { SetupPage::log_info("memory_limit increased from {$iMemoryLimit} to " . SAFE_MINIMUM_MEMORY . "."); } } } function FatalErrorCatcher($sOutput) { if (preg_match('|<phpfatalerror>.*</phpfatalerror>|s', $sOutput, $aMatches)) { header("HTTP/1.0 500 Internal server error."); $errors = ''; foreach ($aMatches as $sMatch) { $errors .= strip_tags($sMatch) . "\n";