first commit
This commit is contained in:
120
plugins/tms_link/hooks/all.php
Normal file
120
plugins/tms_link/hooks/all.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
include_once __DIR__ . "/../include/tms_link_functions.php";
|
||||
|
||||
|
||||
function HookTms_linkAllInitialise()
|
||||
{
|
||||
$tms_link_config = get_plugin_config('tms_link');
|
||||
if (isset($tms_link_config["tms_link_log_directory"])) {
|
||||
// Legacy config - remove from plugin settings
|
||||
save_removed_ui_config('tms_link_log_directory');
|
||||
unset($tms_link_config["tms_link_log_directory"]);
|
||||
set_plugin_config('tms_link', $tms_link_config);
|
||||
}
|
||||
check_removed_ui_config("tms_link_log_directory");
|
||||
|
||||
if(is_null($tms_link_config) || get_sysvar(TMS_LINK_MODULES_MIGRATED) !== false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$new_module = array(
|
||||
'tms_uid_field' => ''
|
||||
);
|
||||
$config_migration_map = array(
|
||||
'tms_link_table_name' => 'module_name',
|
||||
'tms_link_object_id_field' => 'rs_uid_field',
|
||||
'tms_link_checksum_field' => 'checksum_field',
|
||||
'tms_link_resource_types' => 'applicable_resource_types',
|
||||
|
||||
);
|
||||
|
||||
foreach($tms_link_config as $name => $value)
|
||||
{
|
||||
if(!array_key_exists($name, $config_migration_map))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_module[$config_migration_map[$name]] = $value;
|
||||
}
|
||||
|
||||
$tms_rs_mappings = array();
|
||||
foreach(unserialize(base64_decode($GLOBALS['tms_link_field_mappings_saved'])) as $tms_column => $rs_field)
|
||||
{
|
||||
$new_column = array(
|
||||
'tms_column' => $tms_column,
|
||||
'rs_field' => $rs_field,
|
||||
);
|
||||
|
||||
$new_column['encoding'] = 'UTF-8';
|
||||
if(in_array($tms_column, $GLOBALS['tms_link_text_columns']))
|
||||
{
|
||||
$new_column['encoding'] = 'UTF-16';
|
||||
}
|
||||
|
||||
$tms_rs_mappings[] = $new_column;
|
||||
}
|
||||
$new_module['tms_rs_mappings'] = $tms_rs_mappings;
|
||||
$tms_link_modules_mappings[uniqid()] = $new_module;
|
||||
|
||||
$tms_link_config['tms_link_modules_saved_mappings'] = base64_encode(serialize($tms_link_modules_mappings));
|
||||
|
||||
set_plugin_config('tms_link', $tms_link_config);
|
||||
|
||||
set_sysvar(TMS_LINK_MODULES_MIGRATED, 1);
|
||||
}
|
||||
|
||||
|
||||
function HookTms_linkAllUpdate_field($resource, $field, $value, $existing)
|
||||
{
|
||||
if($resource < 0 || !tms_link_is_rs_uid_field($field))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$resdata = get_resource_data($resource);
|
||||
foreach(tms_link_get_modules_mappings() as $module)
|
||||
{
|
||||
if(!in_array($resdata['resource_type'], $module['applicable_resource_types']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$tms_object_id = intval($value);
|
||||
debug("tms_link: updating resource id #" . $resource);
|
||||
|
||||
$module_name = $module['module_name'];
|
||||
$tmsdata = tms_link_get_tms_data($resource, $tms_object_id,'', $module_name);
|
||||
|
||||
// if call to tms_link_get_tms_data() does not return an array, error has occurred
|
||||
if (!is_array($tmsdata))
|
||||
{
|
||||
return $tmsdata; // return error message
|
||||
}
|
||||
|
||||
if(!array_key_exists($module_name, $tmsdata))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($module['tms_rs_mappings'] as $tms_rs_mapping)
|
||||
{
|
||||
if($tms_rs_mapping['rs_field'] > 0 && $module['rs_uid_field'] != $tms_rs_mapping['rs_field'] && isset($tmsdata[$module_name][$tms_rs_mapping['tms_column']]))
|
||||
{
|
||||
debug("tms_link: updating field '{$field}' with data from column '{$tms_rs_mapping['tms_column']}' for resource id #{$resource}");
|
||||
|
||||
update_field($resource, $tms_rs_mapping['rs_field'], $tmsdata[$module_name][$tms_rs_mapping['tms_column']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tms_link_check_preview($resource);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function HookTms_linkAllAfterpreviewcreation($ref, $alternative=-1, $generateall = false)
|
||||
{
|
||||
tms_link_check_preview($ref, $alternative);
|
||||
}
|
13
plugins/tms_link/hooks/check.php
Normal file
13
plugins/tms_link/hooks/check.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
function HookTms_linkCheckAddinstallationcheck()
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<td class="BorderBottom"; colspan='3'>
|
||||
<b>TMS link</b>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
display_extension_status("odbc");
|
||||
}
|
||||
|
19
plugins/tms_link/hooks/cron_copy_hitcount.php
Normal file
19
plugins/tms_link/hooks/cron_copy_hitcount.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
function HookTms_linkCron_copy_hitcountAddplugincronjob()
|
||||
{
|
||||
global $php_path,$config_windows, $tms_link_enable_update_script;
|
||||
if(!$tms_link_enable_update_script){return false;}
|
||||
if (isset($php_path) && (file_exists($php_path . "/php") || ($config_windows && file_exists($php_path . "/php.exe"))))
|
||||
{
|
||||
echo "\r\nRunning TMS update script....\r\n";
|
||||
echo "COMMAND: \"" . $php_path . (($config_windows)?"/php.exe\" ":"/php\" ") . __DIR__ . "/../pages/tms_update_script.php";
|
||||
run_command("\"" . $php_path . (($config_windows)?"/php.exe\" ":"/php\" ") . __DIR__ . "/../pages/tms_update_script.php");
|
||||
echo "\r\nTMS update script started, please check setup page to ensure script has completed.\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "TMS script failed - \$php_path variable must be set in config.php\r\n";
|
||||
}
|
||||
|
||||
}
|
205
plugins/tms_link/hooks/edit.php
Normal file
205
plugins/tms_link/hooks/edit.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
function HookTms_linkEditEditbeforesectionhead()
|
||||
{
|
||||
global $lang,$baseurl,$tms_link_object_id_field, $ref,$resource,$tms_confirm_upload,$tms_link_resource_types;
|
||||
|
||||
if($ref > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$resource_type_allowed = array();
|
||||
|
||||
foreach(tms_link_get_modules_mappings() as $module_uid => $module)
|
||||
{
|
||||
if(!in_array($resource['resource_type'], $module['applicable_resource_types']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$resource_type_allowed[] = true;
|
||||
$field_label = str_replace(
|
||||
array("%module_name", "%tms_uid_field"),
|
||||
array($module['module_name'], $module['tms_uid_field']),
|
||||
$lang["tms_link_uid_field"]);
|
||||
$input_identifier = "field_{$module_uid}_{$module['rs_uid_field']}";
|
||||
?>
|
||||
<div class="Question">
|
||||
<label for="<?php echo $input_identifier; ?>"><?php echo $field_label; ?></label>
|
||||
<input id="<?php echo $input_identifier; ?>" name="<?php echo $input_identifier; ?>" type="text" value="<?php echo escape(get_data_by_field($ref, $module['rs_uid_field'])); ?>">
|
||||
<div class="clearerleft"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if(!empty($resource_type_allowed) && isset($tms_confirm_upload) && $tms_confirm_upload)
|
||||
{
|
||||
?>
|
||||
<div class="Question FieldSaveError" id="tms_confirm_upload">
|
||||
<label for="tms_confirm_upload"><?php echo escape($lang["tms_link_confirm_upload_nodata"]); ?></label>
|
||||
<input type="checkbox" id="tms_confirm_upload" name="tms_confirm_upload" value="true">
|
||||
<div class="clearerleft"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
function HookTMS_linkEditEdithidefield($field)
|
||||
{
|
||||
global $tms_link_object_id_field,$ref,$resource,$tms_link_resource_types;
|
||||
|
||||
$field_ref_ok = false;
|
||||
$resource_type_allowed = false;
|
||||
|
||||
if(tms_link_is_rs_uid_field($field['ref']) && $ref < 0)
|
||||
{
|
||||
$field_ref_ok = true;
|
||||
}
|
||||
|
||||
foreach(tms_link_get_modules_mappings() as $module)
|
||||
{
|
||||
if(in_array($resource['resource_type'], $module['applicable_resource_types']))
|
||||
{
|
||||
$resource_type_allowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($field_ref_ok && $resource_type_allowed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function HookTms_linkAllAdditionalvalcheck($fields, $fieldsitem)
|
||||
{
|
||||
global $ref,$val,$tms_link_object_id_field,$resource,$tms_link_resource_types,$lang;
|
||||
|
||||
if(!tms_link_is_rs_uid_field($fieldsitem['ref']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach(tms_link_get_modules_mappings() as $module_uid => $module)
|
||||
{
|
||||
if(!in_array($resource['resource_type'], $module['applicable_resource_types']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$input_identifier = ($ref < 0) ? "field_{$module_uid}_{$module['rs_uid_field']}" : "field_{$module['rs_uid_field']}";
|
||||
$tms_form_post_id = getval($input_identifier, 0, true);
|
||||
if($tms_form_post_id == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$tms_object_id = intval($tms_form_post_id);
|
||||
|
||||
global $tmsdata;
|
||||
$tmsdata = tms_link_get_tms_data('', $tms_object_id, '', $module['module_name']);
|
||||
|
||||
// Make sure we actually do save this data, even if we return an error
|
||||
$result_update_field = update_field($ref, $module['rs_uid_field'], $tms_object_id);
|
||||
if ($result_update_field !== true)
|
||||
{
|
||||
return $result_update_field; // return error message
|
||||
}
|
||||
|
||||
if(!is_array($tmsdata) && $ref < 0)
|
||||
{
|
||||
// We can't get any data from TMS for this new resource. Need to show warning if user has not already accepted this
|
||||
if(getval("tms_confirm_upload","")=="")
|
||||
{
|
||||
global $tms_confirm_upload, $lang;
|
||||
$tms_confirm_upload=true;
|
||||
return $lang["tms_link_upload_nodata"] . $tms_form_post_id . " " . $lang["tms_link_confirm_upload_nodata"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
global $tms_link_import;
|
||||
|
||||
$tms_link_import=true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function HookTms_linkEditSaveextraresourcedata($list)
|
||||
{
|
||||
// Multi edit - set flag to update TMS data if necessary
|
||||
foreach(tms_link_get_modules_mappings() as $module)
|
||||
{
|
||||
$tms_object_id = getval("field_{$module['rs_uid_field']}", 0, true);
|
||||
|
||||
if($tms_object_id == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
global $tmsdata;
|
||||
$tmsdata = tms_link_get_tms_data('', $tms_object_id, '', $module['module_name']);
|
||||
|
||||
if(!is_array($tmsdata))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
global $tms_link_import, $tmsupdatelist;
|
||||
$tms_link_import = true;
|
||||
$tmsupdatelist = $list;
|
||||
}
|
||||
}
|
||||
|
||||
function HookTms_linkEditAftersaveresourcedata()
|
||||
{
|
||||
global $tms_link_import;
|
||||
|
||||
if(isset($tms_link_import) && !$tms_link_import)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global $ref, $tmsdata, $tmsupdatelist;
|
||||
|
||||
if(is_null($tmsdata) || !is_array($tmsdata))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_array($tmsupdatelist))
|
||||
{
|
||||
$tmsupdatelist = array();
|
||||
$tmsupdatelist[] = $ref;
|
||||
}
|
||||
|
||||
foreach($tmsupdatelist as $resourceref)
|
||||
{
|
||||
debug("tms_link: updating resource id #{$resourceref}");
|
||||
|
||||
foreach(tms_link_get_modules_mappings() as $module)
|
||||
{
|
||||
if(!array_key_exists($module['module_name'], $tmsdata))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($module['tms_rs_mappings'] as $tms_rs_mapping)
|
||||
{
|
||||
if($tms_rs_mapping['rs_field'] > 0 && $module['rs_uid_field'] != $tms_rs_mapping['rs_field'] && isset($tmsdata[$module['module_name']][$tms_rs_mapping['tms_column']]))
|
||||
{
|
||||
update_field($resourceref, $tms_rs_mapping['rs_field'], $tmsdata[$module['module_name']][$tms_rs_mapping['tms_column']]);
|
||||
}
|
||||
elseif($resourceref > 0 && getval("field_{$module['rs_uid_field']}", '') == '')
|
||||
{
|
||||
update_field($resourceref, $tms_rs_mapping['rs_field'], '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
plugins/tms_link/hooks/team_home.php
Normal file
16
plugins/tms_link/hooks/team_home.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
function HookTms_linkTeam_homeCustomteamfunctionadmin()
|
||||
{
|
||||
global $lang, $tms_link_script_failure_notify_days;
|
||||
$scriptlastran=ps_value("select value from sysvars where name='last_tms_import'", array(), "");
|
||||
$tms_link_script_failure_notify_seconds=intval($tms_link_script_failure_notify_days)*60*60*24;
|
||||
|
||||
if($scriptlastran=="" || time()>=(strtotime($scriptlastran)+$tms_link_script_failure_notify_seconds))
|
||||
{
|
||||
$tmsalerthtml="<p>" . str_replace("%days%",$tms_link_script_failure_notify_days,$lang["tms_link_script_problem"]) . " " . (($scriptlastran!="")?date("l F jS Y @ H:m:s",strtotime($scriptlastran)):$lang["status-never"]) . "</p>";
|
||||
echo $tmsalerthtml;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
32
plugins/tms_link/hooks/view.php
Normal file
32
plugins/tms_link/hooks/view.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
function HookTms_linkViewRenderfield($field)
|
||||
{
|
||||
if (!checkperm("a")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $baseurl,$search, $ref;
|
||||
|
||||
if (tms_link_is_rs_uid_field($field["ref"]) && $field["value"] != "") {
|
||||
$tmsid = $field["value"];
|
||||
$value = highlightkeywords(escape($tmsid), escape($search), $field["partial_index"], $field["name"], $field["keywords_index"]);
|
||||
$title = escape($field["title"]);
|
||||
$a_href = generateURL(
|
||||
"{$baseurl}/plugins/tms_link/pages/tms_details.php",
|
||||
array(
|
||||
'ref' => $ref,
|
||||
'tmsid' => $tmsid,
|
||||
)
|
||||
);
|
||||
?>
|
||||
<div class="itemNarrow">
|
||||
<h3><?php echo escape($title); ?></h3>
|
||||
<p>
|
||||
<a href="<?php echo $a_href; ?>" onclick="return ModalLoad(this,true)"><?php echo $value; ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user