function ImportReport($RptName) { global $db; if ($_POST['RptFileName'] != '') { // then a locally stored report was chosen $arrSQL = file(DIR_FS_REPORTS . $_POST['RptFileName']); } else { // check for an uploaded file $Rtn['result'] = 'error'; if ($_FILES['reportfile']['error']) { // php error uploading file switch ($_FILES['reportfile']['error']) { case '1': $Rtn['message'] = TEXT_IMP_ERMSG1; break; case '2': $Rtn['message'] = TEXT_IMP_ERMSG2; break; case '3': $Rtn['message'] = TEXT_IMP_ERMSG3; break; case '4': $Rtn['message'] = TEXT_IMP_ERMSG4; break; default: $Rtn['message'] = TEXT_IMP_ERMSG5 . $_FILES['reportfile']['error'] . '.'; } } elseif (!is_uploaded_file($_FILES['reportfile']['tmp_name'])) { // file uploaded $Rtn['message'] = TEXT_IMP_ERMSG10; } elseif (strpos($_FILES['reportfile']['type'], 'text') === false) { // not a text file, error $Rtn['message'] = TEXT_IMP_ERMSG6; } elseif ($_FILES['reportfile']['size'] == 0) { // report contains no data, error $Rtn['message'] = TEXT_IMP_ERMSG7; } else { // passed all error checking, read file and reset error message $arrSQL = file($_FILES['reportfile']['tmp_name']); $Rtn['result'] = ''; } if ($Rtn['result'] == 'error') { return $Rtn; } } if (is_array($arrSQL)) { foreach ($arrSQL as $sql) { // find the report translated description and title information if (strpos($sql, 'ReportName:') === 0) { $ReportName = substr(trim($sql), 12, -1); } } } // check for valid file, duplicate report name if ($RptName == '') { $RptName = $ReportName; } // then no report was entered use description from file $sql = "select id from " . TABLE_REPORTS . " where description = '" . addslashes($RptName) . "'"; $result = $db->Execute($sql); if ($result->RecordCount() > 0) { // the report name already exists, error $Rtn['result'] = 'error'; $Rtn['message'] = RW_RPT_REPDUP; return $Rtn; } // Find the line with the table reports element, needs to be written first $ValidReportSQL = false; if (is_array($arrSQL)) { foreach ($arrSQL as $sql) { // find the main reports sql statement, language and execute it if (strpos($sql, 'ReportData:') === 0) { $values = substr(trim($sql), 11); $values = substr($values, 0, strlen($values) - 1); $data_array = explode(',', $values); $sql_array = array(); foreach ($data_array as $value) { $parts = explode('=', $value, 2); $sql_array[trim($parts[0])] = substr(trim($parts[1]), 1, -1); } $sql = "insert into " . TABLE_REPORTS . " set \r\n\t\t\t\tdescription = '" . $sql_array['description'] . "', \r\n\t\t\t\treporttype = '" . $sql_array['reporttype'] . "', \r\n\t\t\t\tgroupname = '" . $sql_array['groupname'] . "', \r\n\t\t\t\tstandard_report = '" . $sql_array['standard_report'] . "', \r\n\t\t\t\tspecial_report = '" . $sql_array['special_report'] . "', \r\n\t\t\t\ttable1 = '" . $sql_array['table1'] . "', \r\n\t\t\t\ttable2 = '" . $sql_array['table2'] . "', \r\n\t\t\t\ttable2criteria = '" . $sql_array['table2criteria'] . "', \r\n\t\t\t\ttable3 = '" . $sql_array['table3'] . "', \r\n\t\t\t\ttable3criteria = '" . $sql_array['table3criteria'] . "', \r\n\t\t\t\ttable4 = '" . $sql_array['table4'] . "', \r\n\t\t\t\ttable4criteria = '" . $sql_array['table4criteria'] . "', \r\n\t\t\t\ttable5 = '" . $sql_array['table5'] . "', \r\n\t\t\t\ttable5criteria = '" . $sql_array['table5criteria'] . "', \r\n\t\t\t\ttable6 = '" . $sql_array['table6'] . "', \r\n\t\t\t\ttable6criteria = '" . $sql_array['table6criteria'] . "'"; $result = $db->Execute($sql); // fetch the id of the row inserted $ReportID = $db->insert_ID(); if (isset($sql_array['papersize'])) { load_page_fields($sql_array, $ReportID); } // for pre-release reports and forms $ValidReportSQL = true; } } } if (!$ValidReportSQL) { // no valid report sql statement found in the text file, error $Rtn['result'] = 'error'; $Rtn['message'] = TEXT_IMP_ERMSG8; return $Rtn; } // update the translated report name and title fields into the newly imported report $sql = "update " . TABLE_REPORTS . " set description = '" . $RptName . "' where id = " . $ReportID; $result = $db->Execute($sql); foreach ($arrSQL as $sql) { // fetch the translations for the field descriptions if (strpos($sql, 'FieldDesc') === 0) { // then it's a field description, find the index and save $sql = trim($sql); $FldIndex = substr($sql, 9, strpos($sql, ':') - 9); $Language[$FldIndex] = substr($sql, strpos($sql, ':') + 2, -1); } } $needs_update = false; foreach ($arrSQL as $sql) { if (strpos($sql, 'FieldData') === 0) { // a valid field, write it $sql = trim($sql); $FldIndex = substr($sql, 9, strpos($sql, ':') - 9); $sql = "insert into " . TABLE_REPORT_FIELDS . " set " . substr($sql, strpos($sql, ':') + 1); // check for update required (for Pre R1.9 reports) where some fields have been combined if (strpos($sql, 'dateselect') || strpos($sql, 'trunclong')) { $needs_update = true; } $result = $db->Execute($sql); $FieldID = $db->insert_ID(); if ($FieldID != 0) { // A field was successfully written update the report id $DispSQL = isset($Language[$FldIndex]) ? "displaydesc='" . $Language[$FldIndex] . "', " : ''; $sql = "update " . TABLE_REPORT_FIELDS . " set " . $DispSQL . " reportid = " . $ReportID . " where id = " . $FieldID; $result = $db->Execute($sql); } } } if ($needs_update) { require_once DIR_FS_MODULES . 'install/functions/install.php'; update_reports(); } $Rtn['result'] = 'success'; $Rtn['message'] = $RptName . TEXT_IMP_ERMSG9; return $Rtn; }
$field_array[] = array(); for ($i = 0; $i < $columns; $i++) { $field_array[] = mysql_field_name($fields, $i); } if (!in_array('printed', $field_array)) { $db->Execute("ALTER TABLE " . TABLE_JOURNAL_MAIN . " ADD printed enum('0','1') NOT NULL DEFAULT '0' AFTER closed"); $db->Execute("ALTER TABLE " . TABLE_JOURNAL_MAIN . " ADD INDEX (closed)"); $db->Execute("ALTER TABLE " . TABLE_JOURNAL_MAIN . " ADD INDEX (bill_acct_id)"); } $fields = mysql_list_fields(DB_DATABASE, TABLE_JOURNAL_ITEM); $columns = mysql_num_fields($fields); $field_array = array(); for ($i = 0; $i < $columns; $i++) { $field_array[] = mysql_field_name($fields, $i); } if (!in_array('project_id', $field_array)) { $db->Execute("CREATE TABLE " . TABLE_PROJECTS_PHASES . " (\r\n\tphase_id int(8) NOT NULL auto_increment,\r\n\tdescription_short varchar(16) collate utf8_unicode_ci NOT NULL default '',\r\n\tdescription_long varchar(64) collate utf8_unicode_ci NOT NULL default '',\r\n\tcost_type varchar(3) collate utf8_unicode_ci default NULL,\r\n\tcost_breakdown enum('0','1') collate utf8_unicode_ci NOT NULL default '0',\r\n\tinactive enum('0','1') collate utf8_unicode_ci NOT NULL default '0',\r\n\tPRIMARY KEY (phase_id),\r\n\tKEY description_short (description_short)\r\n\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Project Phases used for Job Costing'"); $db->Execute("CREATE TABLE " . TABLE_PROJECTS_COSTS . " (\r\n\tcost_id int(8) NOT NULL auto_increment,\r\n\tdescription_short varchar(16) collate utf8_unicode_ci NOT NULL default '',\r\n\tdescription_long varchar(64) collate utf8_unicode_ci NOT NULL default '',\r\n\tcost_type varchar(3) collate utf8_unicode_ci default NULL,\r\n\tinactive enum('0','1') collate utf8_unicode_ci NOT NULL default '0',\r\n\tPRIMARY KEY (cost_id),\r\n\tKEY description_short (description_short)\r\n\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Project Costs used for Job Phase Breakdown'"); $db->Execute("ALTER TABLE " . TABLE_JOURNAL_ITEM . " ADD project_id VARCHAR(16) NULL AFTER serialize_number"); } if (!defined('ROUND_TAX_BY_AUTH')) { $db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " \r\n ( `configuration_title` , `configuration_key` , `configuration_value` , `configuration_description` , `configuration_group_id` , `sort_order` , `last_modified` , `date_added` , `use_function` , `set_function` ) \r\n VALUES ( 'CD_01_52_TITLE', 'ROUND_TAX_BY_AUTH', '0', 'CD_01_52_DESC', '1', '52', NULL , now(), NULL , 'cfg_keyed_select_option(array(0 =>\\'" . TEXT_NO . "\\', 1=>\\'" . TEXT_YES . "\\'),' );"); // add gl_type to adjustments for ajaz page loading $result = $db->Execute("update " . TABLE_JOURNAL_MAIN . " m inner join " . TABLE_JOURNAL_ITEM . " i on m.id = i.ref_id \r\n\tset i.gl_type = 'adj' where m.journal_id = 16 and i.gl_type = '' and i.sku <> ''"); $result = $db->Execute("update " . TABLE_JOURNAL_MAIN . " m inner join " . TABLE_JOURNAL_ITEM . " i on m.id = i.ref_id \r\n\tset i.gl_type = 'ttl' where m.journal_id = 16 and i.gl_type = '' and i.sku = ''"); // change printed type to integer for incrmenting print counts of a record $result = $db->Execute("ALTER TABLE " . TABLE_JOURNAL_MAIN . " CHANGE printed printed INT( 11 ) NOT NULL DEFAULT '0'"); // update reports require_once DIR_FS_MODULES . 'install/functions/install.php'; update_reports(); }