function mod_save($idmod_in, $name, $verbose, $description, $modversion, $modcat, $input, $output, $idclient, $repid = '', $sql_install = '', $sql_uninstall = '', $sql_update = '', $mod_rebuild_sql = false, $source_id = '0', $mod_no_wedding = false, $stripe = false, $mod_config_takeover = false) { global $db, $auth, $cms_db, $cfg_cms, $cms_lang, $cfg_client, $rep, $perm; global $idmod; //make global for header redirect $idmod = $idmod_in; // Eintrag in 'mod' Tabelle if (empty($name) || $name == '') { $name = $cms_lang['mod_defaultname']; } if (empty($modversion) || $modversion == '') { $modversion = '1.0'; } if ($stripe == 1) { $name = make_string_dump($name); $verbose = make_string_dump($verbose); $description = make_string_dump($description); $modversion = make_string_dump($modversion); $modcat = make_string_dump($modcat); $input = make_string_dump($input); $output = make_string_dump($output); } elseif ($stripe != 2) { set_magic_quotes_gpc($name); set_magic_quotes_gpc($verbose); set_magic_quotes_gpc($description); set_magic_quotes_gpc($modversion); set_magic_quotes_gpc($modcat); set_magic_quotes_gpc($input); set_magic_quotes_gpc($output); } $checked = ($err_i = $rep->mod_test(cms_stripslashes($input), $idmod)) || ($err_0 = $rep->mod_test(cms_stripslashes($output), $idmod)) ? '0' : '1'; $modverbose = $verbose == '-1' ? $name : $verbose; $mod_sql_uninstall = $sql_uninstall; $mod_sql_install = $sql_install; $sql_install = mysql_escape_string($rep->decode_sql($sql_install)); $sql_uninstall = mysql_escape_string($rep->decode_sql($sql_uninstall)); $sql_update = mysql_escape_string($rep->decode_sql($sql_update)); if ($mod_no_wedding == true) { $source_id = 0; $repositoryid = $rep->gen_new_mod($name); $update_source = ", source_id='0'"; } elseif ($source_id) { $repositoryid = $rep->gen_new_mod($name, true); } elseif ($repid == '') { $repositoryid = $rep->gen_new_mod($name); if ($errno = $rep->error(true)) { return $errno; } } else { $repositoryid = $rep->gen_new_mod($name, true); } if ($errno = $rep->error(true)) { return $errno; } elseif (empty($input) && empty($output)) { return '0424'; } if (!$idmod) { // Modul existiert noch nicht $sql = "INSERT INTO\r\n\t\t\t\t" . $cms_db['mod'] . "\r\n\t\t\t\t(name, description, version, cat, input, output, idclient, author, created, lastmodified,\r\n\t\t\t\trepository_id, install_sql, uninstall_sql, update_sql, source_id, verbose, checked)\r\n\t\t\t\tVALUES\r\n\t\t\t\t('{$name}', '{$description}', '{$modversion}', '{$modcat}', '{$input}', '{$output}', '{$idclient}',\r\n\t\t\t\t'" . $auth->auth['uid'] . "', '" . time() . "', '" . time() . "', '{$repositoryid}', '{$sql_install}', '{$sql_uninstall}', '{$sql_update}', '{$source_id}', '{$modverbose}', '{$checked}')"; $affect = $db->query($sql); if (!$affect || $affect < 1) { return '0400'; } $idmod = $last_id = $db->insert_id(); if ($mod_config_takeover == true) { $modul = $rep->mod_data($source_id, $idclient); mod_save_config($idmod, make_string_dump($modul['config'])); } // Event fire_event('mod_new', array('idmod' => $idmod, 'name' => $name)); } else { // hat sich das Modul geändert? $sql = "SELECT output FROM " . $cms_db['mod'] . " WHERE idmod='{$idmod}'"; $db->query($sql); $db->next_record(); $output_old = $db->f('output'); set_magic_quotes_gpc($output_old); //don't change verbose name by sql update if ($verbose == '-2') { $sql_verbose_name = ''; } else { $sql_verbose_name = "verbose = '{$modverbose}',"; } if ($output != $output_old) { $sql = "UPDATE " . $cms_db['mod'] . "\r\n\t\t\t\t\tSET\r\n\t\t\t\t\tname='{$name}', description='{$description}', version = '{$modversion}', cat = '{$modcat}',\r\n\t\t\t\t\tinput='{$input}', output='{$output}', author='" . $auth->auth['uid'] . "', lastmodified='" . time() . "',\r\n\t\t\t\t\tinstall_sql ='{$sql_install}', uninstall_sql ='{$sql_uninstall}', update_sql ='{$sql_update}' {$update_source}, repository_id = '{$repositoryid}', {$sql_verbose_name} checked = '{$checked}'\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\tidmod='{$idmod}'"; $db->query($sql); $change = 'true'; } else { $sql = "UPDATE " . $cms_db['mod'] . "\r\n\t\t\t\t\tSET\r\n\t\t\t\t\tname='{$name}', description='{$description}', version = '{$modversion}', cat = '{$modcat}', input='{$input}',\r\n\t\t\t\t\tauthor='" . $auth->auth['uid'] . "', lastmodified='" . time() . "', install_sql='{$sql_install}',\r\n\t\t\t\t\tuninstall_sql='{$sql_uninstall}', update_sql='{$sql_update}' {$update_source}, repository_id = '{$repositoryid}', {$sql_verbose_name} checked = '{$checked}'\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\tidmod='{$idmod}'"; $db->query($sql); } // Event fire_event('mod_edit', array('idmod' => $idmod, 'name' => $name)); } if ($idclient > 0 && $mod_sql_install != '' && $mod_rebuild_sql == true) { if ($mod_sql_uninstall != '') { $error = $rep->bulk_sql($mod_sql_uninstall); } if (!$error) { $error = $rep->bulk_sql($mod_sql_install); } if (!$error) { $sql = "UPDATE " . $cms_db['mod'] . " SET is_install='1', lastmodified='" . time() . "' WHERE idmod='{$idmod}'"; $db->query($sql); } // Event fire_event('mod_install_sql', array('idmod' => $idmod, 'name' => $name)); } if ($change) { // Status der 'code' Tabelle ändern $list = get_idtplconf_by_using_type($idmod, 'mod'); $list = get_idcode_by_idtplconf($list); change_code_status($list, '1'); unset($list); } // Rechte setzen if ($perm->have_perm('6', 'mod', $idmod)) { global $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben; $perm->set_group_rights('mod', $idmod, $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben, '', 0xafd); } return !$error ? '0412' : $error; }
/** * repository::mod_import() * * install a Module in the $idclient Client and returns the new idmod * * @param string $xmlstring Module Content * @param integer $idclient Client Id */ function mod_import($xmlstring = '', $idclient = '0', $override = false, $module = array(NULL), $cmodule = array(NULL), $smodule = array(NULL), $rmodule = array(NULL)) { if ($xmlstring == '' || !is_array($xml_array = $this->cms_mod($xmlstring))) { return array('-7', false); } if ($xml_array['repository_id'] == '') { $xml_array['repository_id'] = $this->gen_new_mod($xml_array['name'], true); } $items = $this->rep_local_count($idclient, 'mod'); //Debug me! print_r($items); list($type, $rid, $uid) = explode(":", $xml_array['repository_id']); $repid = $type . ':' . $rid; if ($idclient != '0' && count($items['rep']["{$idclient}"]["{$repid}"]) >= 1) { foreach ($items['rep']["{$idclient}"]["{$repid}"] as $modul) { if (lib_floatval($xml_array['version']) > lib_floatval($modul['version'])) { if (!$override) { return array('-1', $xml_array); } else { $idmod['update'][] = $modul['idmod']; } } elseif (lib_floatval($xml_array['version']) == lib_floatval($modul['version'])) { if (!$override) { return array('-3', $xml_array); } else { $idmod['reinstall'][] = $modul['idmod']; } } } } elseif ($idclient == '0' && count($items['rep']["{$repid}"]) >= 1) { foreach ($items['rep']["{$repid}"] as $modul) { if (lib_floatval($xml_array['version']) > lib_floatval($modul['version']) && $modul['idclient'] == '0') { if (!$override) { return array('-2', $xml_array); } else { $idmod['update'][] = $modul['idmod']; } } elseif (lib_floatval($xml_array['version']) == lib_floatval($modul['version']) && $modul['idclient'] == '0') { if (!$override) { return array('-3', $xml_array); } else { $idmod['reinstall'][] = $modul['idmod']; } } } } if (!$override) { return array($this->_mod_import($xml_array, $idclient), $xml_array); } elseif (is_array($idmod) && (is_array($module) || is_array($rmodule))) { if ($smodule[$repid]) { $this->_mod_import($xml_array, $idclient); } if (is_array($idmod['reinstall'])) { foreach ($idmod['reinstall'] as $uid) { if ($rmodule["{$uid}"] == true) { mod_lupdate($uid, $xml_array['repository_id'], $xml_array['name'], $xml_array['description'], $xml_array['version'], $xml_array['cat'], $xml_array['input'], $xml_array['output'], $xml_array['sql_install'], $xml_array['sql_uninstall'], $xml_array['sql_update'], $idclient, true); if ($cmodule["{$uid}"] == false) { mod_save_config($uid, $xml_array['config']); mod_set_config_status($uid); } } } $return = '-5'; } if (is_array($idmod['update'])) { foreach ($idmod['update'] as $uid) { if ($module["{$uid}"] == true) { mod_lupdate($uid, $xml_array['repository_id'], $xml_array['name'], $xml_array['description'], $xml_array['version'], $xml_array['cat'], $xml_array['input'], $xml_array['output'], $xml_array['sql_install'], $xml_array['sql_uninstall'], $xml_array['sql_update'], $idclient, true); if ($cmodule["{$uid}"] == false) { mod_save_config($uid, $xml_array['config']); mod_set_config_status($uid); } } } $return = $return == '-5' ? '-6' : '-4'; } return array($return, $xml_array); } elseif ($smodule[$repid] == true) { return array($this->_mod_import($xml_array, $idclient), $xml_array); } else { return; } return array($idmod, $xml_array); }
if ($cmodule["{$uid}"] == false) { mod_save_config($uid, $updatedata['config']); mod_set_config_all($uid, $updatedata['config']); } else { mod_set_config_status($uid); } $errno = '0420'; } } } if (is_array($rmodule)) { foreach ($rmodule as $uid => $key) { if ($rmodule["{$uid}"] == true) { mod_lupdate($uid, $updatedata['repository_id'], $updatedata['name'], $updatedata['description'], $updatedata['version'], $updatedata['cat'], $updatedata['input'], $updatedata['output'], $updatedata['install_sql'], $updatedata['uninstall_sql'], $updatedata['update_sql'], $idclient); if ($cmodule["{$uid}"] == false) { mod_save_config($uid, $updatedata['config']); mod_set_config_all($uid, $updatedata['config']); } else { mod_set_config_status($uid); } $errno = $errno == '0420' ? '0422' : '0421'; } } } } if (is_array($smodule) && $override == 'true') { if ($smodule[$sourceid] == 'true') { $errno2 = mod_copy($sourceid, '0', $client); } } break;