Support Incident Tracker GIT4.x
triggers.inc.php
Go to the documentation of this file.
00001 <?php
00002 // triggers.inc.php - Trigger definitions and helper functions
00003 //
00004 // SiT (Support Incident Tracker) - Support call tracking system
00005 // Copyright (C) 2010-2011 The Support Incident Tracker Project
00006 // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
00007 //
00008 // This software may be used and distributed according to the terms
00009 // of the GNU General Public License, incorporated herein by reference.
00010 
00017 $actionarray['ACTION_NOTICE'] =
00018 array('name' => $strNotice,
00019       'description' => $strCreateANotice
00020       );
00021 
00022 $actionarray['ACTION_EMAIL'] =
00023 array('name' => $strEmail,
00024       'description' => $strSendAnEmail
00025       );
00026 
00027 $actionarray['ACTION_CREATE_INCIDENT'] =
00028 array('name' => $strNewIncident,
00029       'description' => $strCreateAnIncident,
00030       'requires' => array('updateid'),
00031       'permission' => array(),
00032       'type' => 'system'
00033       );
00034 
00035 $actionarray['ACTION_JOURNAL'] =
00036 array('name' => 'Journal',
00037       'description' => $strLogTriggerInJournal,
00038       'type' => 'system'
00039       );
00040 
00041 plugin_do('trigger_actions');
00042 
00056 $trigger_types['TRIGGER_CONTACT_RESET_PASSWORD'] =
00057 array('name' => $strContactResetPassword,
00058       'description' => $strTriggerContactResetPasswordDesc,
00059       'required' => array('contactid', 'passwordreseturl'),
00060       'type' => 'system'
00061       );
00062 
00063 $trigger_types['TRIGGER_HOLIDAY_REQUESTED'] =
00064 array('name' => $strHolidayRequested,
00065       'description' => $strTriggerHolidayRequestedDesc,
00066       'required' => array('userid', 'approvaluseremail', 'listofholidays'),
00067       'permission' => 'user_permission($_SESSION[\'userid\'], PERM_HOLIDAY_APPROVE);',
00068       'type' => 'system'
00069       );
00070 
00071 $trigger_types['TRIGGER_INCIDENT_ASSIGNED'] =
00072 array('name' => $strIncidentAssigned,
00073       'description' => $strTriggerNewIncidentAssignedDesc,
00074       'required' => array('incidentid', 'userid'),
00075       'object' => 'incident',
00076       'params' => array('ownerid', 'userstatus', 'incidentassigner')
00077       );
00078 
00079 $trigger_types['TRIGGER_INCIDENT_CLOSED'] =
00080 array('name' => $strIncidentClosed,
00081       'description' => $strTriggerIncidentClosedDesc,
00082       'required' => array('incidentid', 'userid', 'notifyexternal', 'notifycontact','awaitingclosure'),
00083       'params' => array('userid', 'externalid', 'externalengineer', 'notifyexternal', 'notifycontact','awaitingclosure')
00084       );
00085 
00086 $trigger_types['TRIGGER_INCIDENT_CREATED'] =
00087 array('name' => $strIncidentCreated,
00088       'description' => $strTriggerNewIncidentCreatedDesc,
00089       'required' => array('incidentid'),
00090       'params' => array('contactid', 'siteid', 'incidentpriorityid', 'contractid', 'slaid', 'salespersonid', 'sendemail')
00091       );
00092 
00093 $trigger_types['TRIGGER_INCIDENT_NEARING_SLA'] =
00094 array('name' => $strIncidentNearingSLA,
00095       'description' => $strTriggerIncidentNearingSLADesc,
00096       'required' => array('incidentid', 'nextslatime', 'nextsla'),
00097       'params' => array('ownerid', 'townerid'),
00098       );
00099 
00100 $trigger_types['TRIGGER_INCIDENT_REVIEW_DUE'] =
00101 array('name' => $strIncidentReviewDue,
00102       'description' => $strTriggerIncidentReviewDueDesc,
00103       'required' => array('incidentid', 'time'),
00104       'params' => array('incidentid'),
00105       );
00106 
00107 $trigger_types['TRIGGER_INCIDENT_UPDATED_EXTERNAL'] =
00108 array('name' => $strIncidentUpdatedExternally,
00109       'description' => $strIncidentUpdatedExternallyDesc,
00110       'required' => array('incidentid'),
00111       'params' => array('incidentid')
00112       );
00113 
00114 $trigger_types['TRIGGER_INCIDENT_UPDATED_INTERNAL'] =
00115 array('name' => $strIncidentUpdatedInternally,
00116       'description' => $strIncidentUpdatedInternallyDesc,
00117       'required' => array('incidentid', 'userid'),
00118       'params' => array('incidentid', 'userid')
00119       );
00120 
00121 $trigger_types['TRIGGER_KB_CREATED'] =
00122 array('name' => $strKnowledgeBaseArticleCreated,
00123       'description' => $strTriggerKBArticleCreatedDesc,
00124       'required' => array('kbid', 'userid'),
00125       'params' => array('userid'),
00126       );
00127 
00128 $trigger_types['TRIGGER_LANGUAGE_DIFFERS'] =
00129 array('name' => $strCurrentLanguageDiffers,
00130       'description' => $strTriggerLanguageDiffersDesc,
00131       'required' => array('currentlang', 'profilelang'),
00132       'params' => array()
00133     );
00134 
00135 $trigger_types['TRIGGER_PORTAL_INCIDENT_CREATED'] =
00136 array('name' => $strPortalIncidentCreated,
00137       'description' => $strTriggerPortalIncidentCreated,
00138       'required' => array('incidentid'),
00139       'params' => array('incidentid', 'contactid', 'siteid', 'incidentpriorityid', 'contractid', 'slaid', 'sitesalespersonid')
00140     );
00141 
00142 $trigger_types['TRIGGER_NEW_CONTACT'] =
00143 array('name' => $strNewContact,
00144       'description' => $strTriggerNewContactDesc,
00145       'required' => array('contactid', 'prepassword', 'userid'),
00146       'params' => array('siteid')
00147       );
00148 
00149 $trigger_types['TRIGGER_NEW_CONTRACT'] =
00150 array('name' => $strNewContract,
00151       'description' => $strTriggerNewContractDesc,
00152       'required' => array('contractid'),
00153       'params' => array('productid', 'slaid')
00154       );
00155 
00156 $trigger_types['TRIGGER_NEW_HELD_EMAIL'] =
00157 array('name' => $strNewHeldEmail,
00158       'description' => $strTriggerNewHeldEmailDesc,
00159       'required' => array('holdingemailid'),
00160       'params' => array('subject', 'contactid', 'siteid'),
00161       );
00162 
00163 $trigger_types['TRIGGER_NEW_SITE'] =
00164 array('name' => $strNewSite,
00165       'description' => $strTriggerNewSiteDesc,
00166       'required' => array('siteid')
00167       );
00168 
00169 $trigger_types['TRIGGER_NEW_USER'] =
00170 array('name' => $strNewUser,
00171       'description' => $strTriggerNewUserDesc,
00172       'required' => array('userid')
00173       );
00174 
00175 $trigger_types['TRIGGER_SCHEDULER_TASK_FAILED'] =
00176 array('name' => $strSchedulerActionFailed,
00177       'description' => $strTriggerSchedulerTaskFailedDesc,
00178       'required' => array('schedulertask'),
00179       'params' => array('schedulertask'),
00180       'perm' => 22
00181       );
00182 
00183 $trigger_types['TRIGGER_SIT_UPGRADED'] =
00184 array('name' => $strSitUpgraded,
00185       'description' => $strTriggerSitUpgradedDesc,
00186       'required' => array('applicationversion'),
00187       'params' => array(),
00188       );
00189 
00190 $trigger_types['TRIGGER_TASK_DUE'] =
00191 array('name' => $strTaskDue,
00192       'description' => $strTaskDueDesc,
00193       'required' => array('taskid'),
00194       'params' => array('userid')
00195       );
00196 
00197 $trigger_types['TRIGGER_USER_CHANGED_STATUS'] =
00198 array('name' => $strUserChangedStatus,
00199       'description' => $strTriggerUserChangedStatusDesc,
00200       'required' => array('userid'),
00201       'params' => array('userid', 'userstatus', 'useraccepting'),
00202       );
00203 
00204 $trigger_types['TRIGGER_USER_RESET_PASSWORD'] =
00205 array('name' => $strUserResetPassword,
00206       'description' => $strTriggerUserResetPasswordDesc,
00207       'required' => array('userid', 'passwordreseturl'),
00208       'type' => 'system'
00209       );
00210 
00211 $trigger_types['TRIGGER_WAITING_HELD_EMAIL'] =
00212 array('name' => $strWaitingHeldEmail,
00213       'description' => $strTriggerNewHeldEmailMinsDesc,
00214       'required' => array('holdingmins', 'notifymins'),
00215       'params' => array('notifymins'),
00216       );
00217 
00218 
00219 $trigger_types['TRIGGER_SERVICE_LIMIT'] =
00220 array('name' => $strBillableIncidentApproved,
00221       'description' => $strBillableIncidentApprovedDesc,
00222       'required' => array('contractid', 'serviceremaining'),
00223       'params' => array('contractid', 'serviceremaining'),
00224       );
00225 
00226 plugin_do('trigger_types');
00227 
00228 // The pairing allows us to define which templates go with which triggers
00229 $email_pair = array('TRIGGER_CONTACT_RESET_PASSWORD' => 'EMAIL_CONTACT_RESET_PASSWORD',
00230                     'TRIGGER_HOLIDAY_REQUESTED' => 'EMAIL_HOLIDAYS_REQUESTED',
00231                     'TRIGGER_INCIDENT_ASSIGNED' => 'EMAIL_INCIDENT_REASSIGNED_USER_NOTIFY',
00232                     'TRIGGER_INCIDENT_CLOSED' => 'EMAIL_INCIDENT_CLOSED_USER',
00233                     'TRIGGER_INCIDENT_CREATED' => 'EMAIL_INCIDENT_CREATED_USER',
00234                     'TRIGGER_INCIDENT_NEARING_SLA' => 'EMAIL_INCIDENT_NEARING_SLA',
00235                     'TRIGGER_INCIDENT_REVIEW_DUE' => 'EMAIL_INCIDENT_REVIEW_DUE',
00236                     'TRIGGER_INCIDENT_UPDATED_EXTERNAL' => 'EMAIL_INCIDENT_UPDATED_CUSTOMER',
00237                     'TRIGGER_INCIDENT_UPDATED_INTERNAL' => 'blank',
00238                     'TRIGGER_KB_CREATED' => 'EMAIL_KB_ARTICLE_CREATED',
00239                     'TRIGGER_LANGUAGE_DIFFERS' => 'blank',
00240                     'TRIGGER_NEW_CONTACT' => 'EMAIL_CONTACT_CREATED',
00241                     'TRIGGER_NEW_CONTRACT' => 'EMAIL_CONTRACT_ADDED',
00242                     'TRIGGER_NEW_HELD_EMAIL' => 'EMAIL_HELD_EMAIL_RECEIVED',
00243                     'TRIGGER_NEW_SITE' => 'EMAIL_SITE_CREATED',
00244                     'TRIGGER_NEW_USER' => 'EMAIL_USER_CREATED',
00245                     'TRIGGER_SCHEDULER_TASK_FAILED' => 'blank',
00246                     'TRIGGER_SIT_UPGRADED' => 'EMAIL_SIT_UPGRADED',
00247                     'TRIGGER_TASK_DUE' => 'blank',
00248                     'TRIGGER_USER_CHANGED_STATUS' => 'blank',
00249                     'TRIGGER_USER_RESET_PASSWORD' => 'EMAIL_USER_RESET_PASSWORD',
00250                     'TRIGGER_WAITING_HELD_EMAIL' => 'EMAIL_HELD_EMAIL_MINS',
00251                     'TRIGGER_SERVICE_LIMIT' => 'EMAIL_SERVICE_LEVEL');
00252 
00253 $notice_pair = array('TRIGGER_INCIDENT_ASSIGNED' => 'NOTICE_INCIDENT_ASSIGNED',
00254                     'TRIGGER_INCIDENT_CLOSED' => 'NOTICE_INCIDENT_CLOSED',
00255                     'TRIGGER_INCIDENT_CREATED' => 'NOTICE_INCIDENT_CREATED',
00256                     'TRIGGER_INCIDENT_NEARING_SLA' => 'NOTICE_INCIDENT_NEARING_SLA',
00257                     'TRIGGER_INCIDENT_REVIEW_DUE' => 'NOTICE_INCIDENT_REVIEW_DUE',
00258                     'TRIGGER_INCIDENT_UPDATED_EXTERNAL' => 'blank',
00259                     'TRIGGER_INCIDENT_UPDATED_INTERNAL' => 'blank',
00260                     'TRIGGER_KB_CREATED' => 'NOTICE_KB_CREATED',
00261                     'TRIGGER_LANGUAGE_DIFFERS' => 'NOTICE_LANGUAGE_DIFFERS',
00262                     'TRIGGER_NEW_CONTACT' => 'NOTICE_NEW_CONTACT',
00263                     'TRIGGER_NEW_CONTRACT' => 'NOTICE_NEW_CONTRACT',
00264                     'TRIGGER_NEW_HELD_EMAIL' => 'NOTICE_NEW_HELD_EMAIL',
00265                     'TRIGGER_NEW_SITE' => 'NOTICE_NEW_SITE',
00266                     'TRIGGER_NEW_USER' => 'NOTICE_NEW_USER',
00267                     'TRIGGER_SCHEDULER_TASK_FAILED' => 'NOTICE_SCHEDULER_TASK_FAILED',
00268                     'TRIGGER_SIT_UPGRADED' => 'NOTICE_SIT_UPGRADED',
00269                     'TRIGGER_TASK_DUE' => 'NOTICE_TASK_DUE',
00270                     'TRIGGER_USER_CHANGED_STATUS' => 'NOTICE_USER_CHANGED_STATUS',
00271                     'TRIGGER_WAITING_HELD_EMAIL' => 'NOTICE_MINS_HELD_EMAIL',
00272                     'TRIGGER_SERVICE_LIMIT' => 'blank');
00273 
00274 
00284 $ttvararray['{applicationname}'] =
00285 array('description' => $CONFIG['application_name'],
00286       'replacement' => '$CONFIG[\'application_name\'];'
00287       );
00288 
00289 $ttvararray['{applicationpath}'] =
00290 array('description' => $strSystemPath,
00291       'replacement' => '$CONFIG[\'application_webpath\'];'
00292       );
00293 
00294 $ttvararray['{applicationshortname}'] =
00295 array('description' => $CONFIG['application_shortname'],
00296       'replacement' => '$CONFIG[\'application_shortname\'];'
00297       );
00298 
00299 $ttvararray['{applicationurl}'] =
00300 array('description' => $strSystemUrl,
00301       'replacement' => 'application_url();'
00302       );
00303 
00304 $ttvararray['{applicationversion}'] =
00305 array('description' => $application_version_string,
00306       'replacement' => 'application_version_string();'
00307       );
00308 
00309 $ttvararray['{approvaluseremail}'] =
00310 array('description' => $strHolidayApproverEmail,
00311       'replacement' => '$param_array[\'approvaluseremail\'];',
00312       'requires' => 'approvaluseremail'
00313       );
00314 
00315 $ttvararray['{awaitingclosure}'] =
00316 array('description' => $strAwaitingClosureVar,
00317       'replacement' => '$param_array[\'awaitingclosure\'];',
00318       'requires' => 'incidentid',
00319       'show' => FALSE
00320       );
00321 
00322 $ttvararray['{contactid}'] =
00323 array('description' => $strContact,
00324       'requires' => 'incidentid',
00325       'replacement' => 'incident_contact($param_array[\'incidentid\']);',
00326       'checkreplace' => 'contact_drop_down',
00327       'show' => FALSE
00328       );
00329 
00330 $ttvararray['{contactemail}'][] =
00331 array('description' => $strIncidentsContactEmail,
00332       'requires' => 'contactid',
00333       'replacement' => 'contact_email($param_array[\'contactid\']);',
00334       'action' => 'ACTION_EMAIL'
00335       );
00336 
00337 $ttvararray['{contactemail}'][] =
00338 array('description' => $strIncidentsContactEmail,
00339       'requires' => 'incidentid',
00340       'replacement' => 'contact_email(incident_contact($param_array[\'incidentid\']));',
00341       'action' => 'ACTION_EMAIL'
00342       );
00343 
00344 $ttvararray['{contactfirstname}'][] =
00345 array('description' => $strContactsForename,
00346       'requires' => 'contactid',
00347       'replacement' => 'strtok(contact_realname($param_array[\'contactid\'])," ");'
00348       );
00349 
00350 $ttvararray['{contactfirstname}'][] =
00351 array('description' => $strContactsForename,
00352       'requires' => 'incidentid',
00353       'replacement' => 'strtok(contact_realname(incident_contact($param_array[\'incidentid\']))," ");'
00354       );
00355 
00356 $ttvararray['{contactid}'][] =
00357 array('description' => $strContact,
00358       'requires' => 'contactid',
00359       'replacement' => '$param_array[\'contactid\'];',
00360       'show' => FALSE
00361       );
00362 
00363 $ttvararray['{contactid}'][] =
00364 array('description' => $strContact,
00365       'requires' => 'incidentid',
00366       'replacement' => 'incident_contact($param_array[\'incidentid\']);',
00367       'show' => FALSE
00368       );
00369 
00370 $ttvararray['{contactname}'][] =
00371 array('description' => $strContactsName,
00372       'requires' => 'contactid',
00373       'replacement' => 'contact_realname($param_array[\'contactid\']);'
00374       );
00375 
00376 $ttvararray['{contactname}'][] =
00377 array('description' => $strContactsName,
00378       'requires' => 'incidentid',
00379       'replacement' => 'contact_realname(incident_contact($param_array[\'incidentid\']));'
00380       );
00381 
00382 $ttvararray['{contactnotify}'] =
00383 array('description' => $strNotifyContactEmail,
00384       'requires' => 'contactid',
00385       'replacement' => 'contact_notify_email($param_array[\'contactid\']);'
00386       );
00387 
00388 $ttvararray['{contactphone}'][] =
00389 array('description' => $strContactsPhone,
00390       'requires' => 'contactid',
00391       'replacement' => 'contact_phone($param_array[\'contactid\']);'
00392       );
00393 
00394 $ttvararray['{contactphone}'][] =
00395 array('description' => $strContactsPhone,
00396       'requires' => 'incidentid',
00397       'replacement' => 'contact_phone(incident_contact($param_array[\'incidentid\']));'
00398       );
00399 
00400 $ttvararray['{contactusername}'] =
00401 array('description' => $strContactsUsername,
00402       'requires' => 'contactid',
00403       'replacement' => 'contact_username($param_array[\'contactid\']);'
00404       );
00405 
00406 $ttvararray['{contractid}'][] =
00407 array('description' => $strContract,
00408       'requires' => 'contractid',
00409       'replacement' => '$param_array[\'contractid\'];',
00410       'checkreplace' => 'maintenance_drop_down',
00411       'show' => FALSE
00412       );
00413 
00414 $ttvararray['{contractid}'][] =
00415 array('description' => $strContract,
00416       'requires' => 'contractid',
00417       'replacement' => 'incident_owner($param_array[\'incidentid\']);',
00418       'checkreplace' => 'maintenance_drop_down',
00419       'show' => FALSE
00420       );
00421 
00422 $ttvararray['{contractproduct}'] =
00423 array('description' => $strContractProduct,
00424       'replacement' => 'contract_product($param_array[\'contractid\']);',
00425       'requires' => 'contractid'
00426       );
00427 
00428 $ttvararray['{contractsla}'] =
00429 array('description' => $strContractsSLA,
00430       'replacement' => 'maintenance_servicelevel_tag($param_array[\'contractid\']);',
00431       'requires' => 'contractid'
00432       );
00433 
00434 $ttvararray['{currentlang}'] =
00435 array('description' => $strCurrentLanguage,
00436       'replacement' => '$param_array[\'currentlang\'];',
00437       'requires' => 'currentlang'
00438       );
00439 
00440 $ttvararray['{emaildetails}'] =
00441 array('show' => FALSE,
00442       'replacement' => '$param_array[\'emaildetails\'];',
00443       );
00444 
00445 $ttvararray['{feedbackurl}'] =
00446 array('description' => $strFeedbackURL,
00447       'requires' => 'incidentid',
00448       'replacement' => 'application_url().\'feedback.php?ax=\'. feedback_hash($CONFIG[\'feedback_form\'], incident_contact($param_array[\'incidentid\']), $param_array[\'incidentid\'], contact_email(incident_contact($param_array[\'incidentid\'])));'
00449       );
00450 
00451 $ttvararray['{feedbackoptout}'] =
00452 array('description' => $strFeedbackOptOutURL,
00453       'requires' => 'incidentid',
00454       'replacement' => 'application_url().\'feedback.php?ou=\'. feedback_opt_out_hash(incident_contact($param_array[\'incidentid\']), contact_email(incident_contact($param_array[\'incidentid\'])));'
00455       );
00456 
00457 
00458 $ttvararray['{formattedtime}'][] =
00459 array('description' => 'Outputs a formatted time, e.g. 2 minutes, 1 hour etc.',
00460       'replacement' => 'format_seconds($param_array[holdingmins] * 60);',
00461       'requires' => 'holdingmins'
00462       );
00463 
00464 $ttvararray['{globalsignature}'] =
00465 array('description' => $strGlobalSignature,
00466       'replacement' => 'global_signature();'
00467       );
00468 
00469 // $ttvararray['{holdingemailid}'] =
00470 // array('description' => 'ID of the new email in the holding queue',
00471 //       'replacement' => '$param_array[\'holdingemailid\'];',
00472 //       'requires' => 'holdingemailid',
00473 //       'show' => FALSE
00474 //       );
00475 
00476 $ttvararray['{holdingmins}'] =
00477 array('description' => $strHoldingQueueMinutes,
00478       'replacement' => '$param_array[\'holdingmins\'];',
00479       'requires' => 'holdingmins'
00480       );
00481 
00482 $ttvararray['{incidentassigner}'] =
00483 array('description' => $strIncidentAssigner,
00484       'replacement' => '$param_array[\'incidentassigner\'];',
00485       'checkreplace' => 'user_drop_down'
00486       );
00487 
00488 $ttvararray['{incidentccemail}'] =
00489 array('description' => $strIncidentCCList,
00490       'requires' => 'incidentid',
00491       'replacement' => 'incident_ccemail($param_array[\'incidentid\']);'
00492       );
00493 
00494 $ttvararray['{incidentexternalemail}'] =
00495 array('description' => $strExternalEngineerEmail,
00496       'requires' => 'incidentid',
00497       'replacement' => 'incident_externalemail($param_array[incidentid]);'
00498       );
00499 
00500 $ttvararray['{incidentexternalengineer}'] =
00501 array('description' => $strExternalEngineer,
00502       'requires' => 'incidentid',
00503       'replacement' => 'incident_externalengineer($param_array[incidentid]);'
00504       );
00505 
00506 $ttvararray['{incidentexternalengineerfirstname}'] =
00507 array('description' => $strExternalEngineersFirstName,
00508       'requires' => 'incidentid',
00509       'replacement' => 'strtok(incident_externalengineer($param_array[\'incidentid\']), " ");'
00510       );
00511 
00512 $ttvararray['{incidentexternalid}'] =
00513 array('description' => $strExternalID,
00514       'requires' => 'incidentid',
00515       'replacement' => 'incident_externalid($param_array[\'incidentid\']);'
00516       );
00517 
00518 $ttvararray['{incidentid}'] =
00519 array('description' => $strIncident,
00520       'requires' => 'incidentid',
00521       'replacement' => '$param_array[\'incidentid\'];',
00522       'checkreplace' => 'incident_drop_down'
00523       );
00524 
00525 $ttvararray['{incidentowner}'] =
00526 array('description' => $strIncidentOwnersFullName,
00527       'requires' => 'incidentid',
00528       'replacement' => 'user_realname(incident_owner($param_array[incidentid]));'
00529       );
00530 
00531 $ttvararray['{incidentowneremail}'] =
00532 array('description' => $strIncidentOwnersEmail,
00533       'requires' => 'incidentid',
00534       'replacement' => 'user_email(incident_owner($param_array[incidentid]));'
00535       );
00536 
00537 $ttvararray['{incidentpriority}'] =
00538 array('description' => $strIncidentPriority,
00539       'requires' => 'incidentid',
00540       'replacement' => 'priority_name(incident_priority($param_array[incidentid]));',
00541       );
00542 
00543 $ttvararray['{incidentpriorityid}'] =
00544 array('description' => $strIncidentPriority,
00545       'requires' => 'incidentid',
00546       'replacement' => 'incident_priority($param_array[incidentid]);',
00547       'show' => FALSE,
00548       'checkreplace' => 'freeform'
00549       );
00550 
00551 $ttvararray['{incidentsoftware}'] =
00552 array('description' => $strSkillAssignedToIncident,
00553       'requires' => 'incidentid',
00554       'replacement' => 'software_name(db_read_column(\'softwareid\', $GLOBALS[\'dbIncidents\'], $param_array[\'incidentid\']));'
00555       );
00556 
00557 $ttvararray['{incidenttitle}'] =
00558 array('description' => $strIncidentTitle,
00559       'requires' => 'incidentid',
00560       'replacement' => 'incident_title($param_array[incidentid]);'
00561       );
00562 
00563 $ttvararray['{kbid}'] =
00564 array('description' => $strKBArticle,
00565       'requires' => 'kbid',
00566       'replacement' => '$param_array[\'kbid\'];'
00567       );
00568 
00569 $ttvararray['{kbprefix}'] =
00570 array('description' => $CONFIG['kb_id_prefix'],
00571       'requires' => array(),
00572       'replacement' => '$CONFIG[\'kb_id_prefix\'];'
00573     );
00574 
00575 $ttvararray['{kbtitle}'] =
00576 array('description' => $strKnowledgeBase,
00577       'requires' => 'kbid',
00578       'replacement' => 'kb_name($param_array[\'kbid\']);'
00579       );
00580 
00581 $ttvararray['{listofholidays}'] =
00582 array('description' => $strListOfHolidays,
00583       'replacement' => '$param_array[\'listofholidays\'];',
00584       'requires' => 'listofholidays'
00585       );
00586 
00587 $ttvararray['{nextslatime}'] =
00588 array('description' => $strTimeToNextAction,
00589       'replacement' => 'format_date_friendly($param_array[\'nextslatime\']);',
00590       'requires' => 'nextslatime'
00591       );
00592 
00593 $ttvararray['{nextsla}'] =
00594 array('description' => $strNextSLATarget,
00595       'replacement' => '$param_array[\'nextsla\'];',
00596       'requires' => 'nextsla'
00597       );
00598 
00599 $ttvararray['{notifycontact}'] =
00600 array('description' => $strNotifyContactOnClose,
00601       'replacement' => '$param_array[\'notifycontact\'];',
00602       'requires' => 'incidentid',
00603       'show' => FALSE
00604       );
00605 
00606 $ttvararray['{notifyexternal}'] =
00607 array('description' => $strNotifyExternalEngineerOnClose,
00608       'replacement' => '$param_array[\'notifyexternal\'];',
00609       'requires' => 'incidentid',
00610       'show' => FALSE
00611       );
00612 
00613 $ttvararray['{notifymins}'] =
00614 array('description' => $strNotifyMinutes,
00615       'replacement' => '$param_array[\'notifymins\'];',
00616       'requires' => 'notifymins',
00617       'show' => TRUE
00618       );
00619 
00620 $ttvararray['{ownerid}'] =
00621 array('description' => $strIncidentOwner,
00622       'replacement' => 'incident_owner($param_array[\'incidentid\']);',
00623       'requires' => 'incidentid',
00624       'checkreplace' => 'user_drop_down',
00625       'show' => FALSE
00626       );
00627 
00628 $ttvararray['{passwordreseturl}'] =
00629 array('description' => $strPasswordResetURL,
00630       'replacement' => '$param_array[\'passwordreseturl\'];',
00631       'requires' => 'passwordreseturl',
00632       'type' => 'system'
00633       );
00634 
00635 $ttvararray['{prepassword}'] =
00636 array('description' => $strContactsPassword,
00637       'replacement' => '$param_array[\'prepassword\'];',
00638       'requires' => 'prepassword',
00639       'type' => 'system'
00640       );
00641 
00642 $ttvararray['{profilelang}'] =
00643 array('description' => $strProfileLanguage,
00644       'replacement' => '$param_array[\'profilelang\'];',
00645       'requires' => 'profilelang'
00646       );
00647 
00648 $ttvararray['{salesperson}'] =
00649 array('description' => $strSalesperson,
00650       'requires' => 'siteid',
00651       'replacement' => 'user_realname(db_read_column(\'owner\', $GLOBALS[\'dbSites\'], $param_array[\'siteid\']));'
00652       );
00653 
00654 $ttvararray['{salespersonid}'] =
00655 array('description' => $strSalesperson,
00656       'requires' => 'siteid',
00657       'show' => FALSE,
00658       'replacement' => 'db_read_column(\'owner\', $GLOBALS[\'dbSites\'], incident_site($param_array[\'incidentid\']));',
00659       'checkreplace' => 'user_drop_down'
00660       );
00661 
00662 $ttvararray['{salespersonemail}'][] =
00663 array('description' => $strSalespersonAssignedToContactsSiteEmail,
00664       'requires' => 'siteid',
00665       'replacement' => 'user_email(db_read_column(\'owner\', $GLOBALS[\'dbSites\'], $param_array[\'siteid\']));'
00666       );
00667 
00668 $ttvararray['{salespersonemail}'][] =
00669 array('description' => $strSalespersonAssignedToContactsSiteEmail,
00670       'requires' => 'contractid',
00671       'replacement' => 'user_email(db_read_column(\'owner\', $GLOBALS[\'dbSites\'], maintenance_siteid($param_array[\'contractid\'])));'
00672       );
00673 
00674 $ttvararray['{schedulertask}'] =
00675 array('description' => $strScheduledTask,
00676       'replacement' => '$param_array[\'schedulertask\'];'
00677     );
00678 
00679 $ttvararray['{sendemail}'] =
00680 array('description' => $strSendOpeningEmailDesc,
00681       'replacement' => '$param_array[\'sendemail\'];',
00682       'show' => FALSE
00683     );
00684 
00685 $ttvararray['{sendfeedback}'] =
00686 array('description' => $strEmailSendFeedbackDesc,
00687       'replacement' => '$param_array[\'sendfeedback\']',
00688       'show' => FALSE);
00689 
00690 $ttvararray['{serviceremaining}'] =
00691 array('description' => $strServiceBalanceInfo,
00692       'requires' => 'contractid',
00693       'replacement' => 'get_service_percentage($param_array[\'contractid\']);',
00694       'show' => FALSE
00695     );
00696 
00697 $ttvararray['{serviceremainingstring}'] =
00698 array('description' => $strServiceBalanceString,
00699       'requires' => 'contractid',
00700       'replacement' => '(get_service_percentage($param_array[\'contractid\']) * 100)."%";',
00701     );
00702 
00703 $ttvararray['{signature}'] =
00704 array('description' => $strCurrentUsersSignature,
00705       'replacement' => 'user_signature($_SESSION[\'userid\']);'
00706       );
00707 
00708 $ttvararray['{siteid}'][] =
00709 array('description' => $strSite,
00710       'requires' => 'siteid',
00711       'replacement' => '$param_array[\'siteid\'];',
00712       'checkreplace' => 'site_drop_down',
00713       'show' => FALSE
00714       );
00715 
00716 $ttvararray['{siteid}'][] =
00717 array('description' => $strSite,
00718       'requires' => 'incidentid',
00719       'replacement' => 'contact_site(incident_contact($param_array[\'incidentid\']));',
00720       'checkreplace' => 'site_drop_down',
00721       'show' => FALSE
00722       );
00723 
00724 $ttvararray['{sitename}'][] =
00725 array('description' => $strSiteName,
00726       'requires' => 'incidentid',
00727       'replacement' => 'contact_site(incident_contact($param_array[\'incidentid\']));'
00728       );
00729 
00730 $ttvararray['{sitename}'][] =
00731 array('description' => $strSiteName,
00732       'requires' => 'contactid',
00733       'replacement' => 'contact_site($param_array[\'contactid\']);'
00734       );
00735 
00736 $ttvararray['{sitename}'][] =
00737 array('description' => $strSiteName,
00738       'requires' => 'contractid',
00739       'replacement' => 'contract_site($param_array[\'contractid\']);'
00740       );
00741 
00742 $ttvararray['{sitename}'][] =
00743 array('description' => $strSiteName,
00744       'requires' => 'siteid',
00745       'replacement' => 'site_name($param_array[\'siteid\']);'
00746       );
00747 
00748 $ttvararray['{sitesalespersonid}'] =
00749 array('description' => $strSalesperson,
00750       'replacement' => 'site_salespersonid($param_array[\'siteid\']);',
00751       'requires' => 'siteid',
00752       'show' => FALSE
00753       );
00754 
00755 $ttvararray['{sitesalesperson}'] =
00756 array('description' => $strSalespersonSite,
00757       'replacement' => 'site_salesperson($param_array[\'siteid\']);',
00758       'requires' => 'siteid'
00759       );
00760 
00761 $ttvararray['{slaactionplan}'] =
00762 array('description' => $strActionPlanSLA,
00763       'replacement' => 'incident_sla($param_array[\'incidentid\'], \'action_plan\');',
00764       'requires' => 'incidentid'
00765       );
00766 
00767 $ttvararray['{slaid}'] =
00768 array('description' => $strSLA,
00769       'replacement' => 'contract_slaid($param_array[\'contractid\']);',
00770       'requires' => 'contractid',
00771       'checkreplace' => 'servicelevel_drop_down',
00772       'show' => FALSE
00773       );
00774 
00775 $ttvararray['{slainitialresponse}'] =
00776 array('description' => $strInitialResponseSLA,
00777       'replacement' => 'incident_sla($param_array[\'incidentid\'], \'initial_response\');',
00778       'requires' => 'incidentid'
00779       );
00780 
00781 $ttvararray['{slaproblemdefinition}'] =
00782 array('description' => $strProblemDefinitionSLA,
00783       'replacement' => 'incident_sla($param_array[\'incidentid\'], \'prob_determ\');',
00784       'requires' => 'incidentid'
00785       );
00786 
00787 $ttvararray['{slatag}'] =
00788 array('description' => $strSLA,
00789       'replacement' => 'maintenance_servicelevel_tag($param_array[\'contractid\']);',
00790       'requires' => 'contractid'
00791       );
00792 
00793 $ttvararray['{slaresolutionreprioritisation}'] =
00794 array('description' => $strResolutionReprioritisationSLA,
00795       'replacement' => 'incident_sla($param_array[\'incidentid\'], \'resolution\');',
00796       'requires' => 'incidentid'
00797       );
00798 
00799 if ($CONFIG['support_email_tags'] === TRUE)
00800 {
00801     $ttvararray['{supportemail}'] =
00802     array('description' => $strSupportEmailAddress,
00803         'replacement' => 'tag_email_address($CONFIG[\'support_email\'], $param_array[\'incidentid\']);',
00804         'requires' => 'incidentid'
00805         );
00806 }
00807 else
00808 {
00809     $ttvararray['{supportemail}'] =
00810     array('description' => $strSupportEmailAddress,
00811         'replacement' => '$CONFIG[\'support_email\'];'
00812         );
00813 }
00814 
00815 
00816 $ttvararray['{supportmanageremail}'] =
00817 array('description' => $strSupportManagersEmailAddress,
00818       'replacement' => 'user_email($CONFIG[\'support_manager\']);'
00819       );
00820 
00821 $ttvararray['{taskid}'] =
00822 array('description' => $strTask,
00823       'replacement' => '$param_array[\'taskid\']',
00824       'show' => FALSE
00825     );
00826 
00827 $ttvararray['{todaysdate}'] =
00828 array('description' => $strCurrentDate,
00829       'replacement' => 'ldate("jS F Y");'
00830       );
00831 
00832 $ttvararray['{townerid}'] =
00833 array('description' => $strTemporaryOwner,
00834       'replacement' => 'incident_towner($param_array[\'incidentid\']);',
00835       'requires' => 'incidentid',
00836       'checkreplace' => 'user_drop_down',
00837       'show' => FALSE
00838       );
00839 
00840 $ttvararray['{triggersfooter}'] =
00841 array('description' => $strTriggersFooter,
00842       'replacement' => '$SYSLANG[\'strTriggerFooter\'];',
00843       'requires' => ''
00844     );
00845 
00846 $ttvararray['{triggeruseremail}'] =
00847 array('description' => $strTriggerUserEmail,
00848       'replacement' => 'user_email($param_array[\'triggeruserid\']);'
00849       );
00850 
00851 $ttvararray['{updateid}'] =
00852 array('description' => 'The ID of the update',
00853       'replacement' => 'incoming_email_update_id($param_array[\'holdingemailid\']);',
00854       'requires' => 'holdingemailid',
00855       'show' => FALSE
00856       );
00857 
00858 $ttvararray['{updatetext}'] =
00859 array('description' => 'By default, the text of the last update to an incident, the numupdates parameter can be set to an integer or -1 for all updates',
00860       'replacement' => 'readable_last_updates($param_array[\'incidentid\'], $param_array[\'numupdates\']);',
00861       'requires' => 'incidentid',
00862       );
00863 
00864 
00865 $ttvararray['{useraccepting}'] =
00866 array('description' => $strAcceptingIncidents,
00867       'replacement' => 'user_accepting_status($param_array[\'userid\']);',
00868       'requires' => 'userid',
00869       'show' => FALSE
00870       );
00871 
00872 $ttvararray['{useremail}'] =
00873 array('description' => $strCurrentUserEmailAddress,
00874       'replacement' => 'user_email($param_array[\'userid\']);'
00875       );
00876 
00877 $ttvararray['{userid}'][] =
00878 array('description' => $strUser,
00879       'replacement' => '$param_array[\'userid\'];',
00880       'checkreplace' => 'user_drop_down',
00881       'show' => FALSE
00882       );
00883 
00884 $ttvararray['{userid}'][] =
00885 array('replacement' => 'task_owner($param_array[\'taskid\']);',
00886       'requires' => 'taskid',
00887       'show' => FALSE
00888       );
00889 
00890 $ttvararray['{userrealname}'] =
00891 array('description' => $strFullNameCurrentUser,
00892       'replacement' => 'user_realname($GLOBALS[\'sit\'][2]);'
00893       );
00894 
00895 $ttvararray['{userstatus}'] =
00896 array('description' => $strUserStatus,
00897       'replacement' => 'user_status_name($param_array[\'userid\']);',
00898       'requires' => 'userid',
00899       'checkreplace' => 'userstatus_drop_down'
00900       );
00901 
00902 plugin_do('trigger_variables');
00903 
00904 
00913 function email_templates($name, $triggertype = 'system', $selected = '')
00914 {
00915     global $dbEmailTemplates, $dbTriggers, $strPersonalTemplates, $strNoResults;
00916     $html .= "<select id='{$name}' name='{$name}'>";
00917 
00918     foreach (array($triggertype, 'usertemplate') as $type)
00919     {
00920         if ($type == 'usertemplate')
00921         {
00922             $html .= "<option disabled='disabled'></option><option disabled='disabled'>=== {$strPersonalTemplates} ===</option>";
00923         }
00924 
00925         $sql = "SELECT id, name, description FROM `{$dbEmailTemplates}` ";
00926         $sql .= "WHERE type='{$type}' ORDER BY name";
00927         $result = mysql_query($sql);
00928         if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
00929         if (mysql_num_rows($result) > 0)
00930         {
00931             while ($template = mysql_fetch_object($result))
00932             {
00933                 //$name = strpos()
00934                 //$name = str_replace("_", " ", $name);
00935                 $name = strtolower($name);
00936                 $html .= "<option id='{$template->name}' value='{$template->name}'>{$GLOBALS[$template->description]} ({$template->name})</option>\n";
00937                 //$html .= "<option disabled='disabled' style='color: #333; text-indent: 10px;' value='{$template->name}'>".$GLOBALS[$template->description]."</option>\n";
00938 
00939             }
00940         }
00941         else
00942         {
00943             $html .= "<option disabled='disabled'>{$strNoResults}</option>";
00944         }
00945 
00946     }
00947     $html .= "</select>\n";
00948     return $html;
00949 }
00950 
00951 
00959 function notice_templates($name, $selected = '')
00960 {
00961     global $dbNoticeTemplates, $strPersonalTemplates;
00962     $html .= "<select id='{$name}' name='{$name}'>";
00963     $sql = "SELECT id, name, description, type FROM `{$dbNoticeTemplates}` ORDER BY type,name ASC";
00964     $query = mysql_query($sql);
00965     if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
00966     while ($template = mysql_fetch_object($query))
00967     {
00968         $user_header = false;
00969         if (!$user_header AND $template->type == USER_DEFINED_NOTICE_TYPE)
00970         {
00971             $user_header = true;
00972             $html .= "<option></option><option>=== {$strPersonalTemplates} ===</option>";
00973         }
00974         $html .= "<option id='{$template->name}' value='{$template->name}'>{$GLOBALS[$template->description]} ({$template->name})</option>\n";
00975     }
00976     $html .= "</select>\n";
00977     return $html;
00978 }
00979 
00980 
00992 function replace_vars($trigger_type, &$ttvar, &$identifier, $param_array, $required = '')
00993 {
00994     global $trigger_types, $ttvararray, $CONFIG;
00995 
00996     $usetvar = FALSE;
00997 
00998     //if we don't have any requires, we can already use this var
00999     if (empty($ttvar['requires']))
01000     {
01001         $usetvar = TRUE;
01002     }
01003     else
01004     {
01005         //otherwise we need to check all the requires
01006         if (!is_array($ttvar['requires']))
01007         {
01008             $ttvar['requires'] = array($ttvar['requires']);
01009         }
01010         //compare the trigger 'provides' with the var 'requires'
01011         foreach ($ttvar['requires'] as $needle)
01012         {
01013             if (is_array($required))
01014             {
01015                 if (in_array($needle, $required))
01016                 {
01017                     $usetvar = TRUE;
01018                 }
01019             }
01020             else
01021             {
01022                 if (in_array($needle, $trigger_types[$trigger_type]['required']))
01023                 {
01024                     $usetvar = TRUE;
01025                 }
01026             }
01027         }
01028     }
01029 
01030     //if we're able to use this variable
01031     if ($usetvar)
01032     {
01033         // debug_log("Using $identifier");
01034         $trigger_regex = "/{$identifier}/s";
01035         if (!empty($ttvar['replacement']))
01036         {
01037             $eresult = eval("\$res = {$ttvar[replacement]};return TRUE;");
01038             if (!$eresult)
01039             {
01040                 trigger_error("Error in variable replacement for
01041                         <strong>{$identifier}</strong>, check that
01042                         this variable is available for the template
01043                         that uses it.", E_USER_WARNING);
01044 
01045                 debug_log("replacement: {$ttvar[replacement]}", TRUE);
01046             }
01047         }
01048 
01049         $trigger_replace = $res;
01050         unset($res);
01051         return array('trigger_replace' => $trigger_replace,
01052                 'trigger_regex' => $trigger_regex);
01053     }
01054 }
01055 
01056 
01064 function replace_specials($string, $param_array)
01065 {
01066     global $CONFIG, $dbg, $dbIncidents, $ttvararray;
01067 
01068     //manual variables
01069     $required = array('incidentid');
01070 
01071     //this loops through each variable and creates an array of useable variables' regexs
01072     foreach ($ttvararray AS $identifier => $ttvar)
01073     {
01074         $multiple = FALSE;
01075         foreach ($ttvar AS $key => $value)
01076         {
01077             //this checks if it's a multiply-defined variable
01078             if (is_numeric($key))
01079             {
01080                 $trigger_replaces = replace_vars($triggerid, $ttvar[$key], $identifier, $param_array, $required);
01081 
01082                 if (!empty($trigger_replaces))
01083                 {
01084                     $trigger_regex[] = $trigger_replaces['trigger_regex'];
01085                     $trigger_replace[] = $trigger_replaces['trigger_replace'];
01086                 }
01087                 $multiple = TRUE;
01088             }
01089         }
01090         if ($multiple == FALSE)
01091         {
01092             $trigger_replaces = replace_vars($triggerid, $ttvar, $identifier, $param_array, $required);
01093             if (!empty($trigger_replaces))
01094             {
01095                 $trigger_regex[] = $trigger_replaces['trigger_regex'];
01096                 $trigger_replace[] = $trigger_replaces['trigger_replace'];
01097             }
01098         }
01099     }
01100 
01101     return preg_replace($trigger_regex, $trigger_replace, $string);
01102 }
01103 
01104 
01113 function trigger_replace_specials($trigger_type, $string_array, $param_array)
01114 {
01115     global $CONFIG, $application_version, $application_version_string, $dbg;
01116     global $dbIncidents;
01117     global $trigger_types, $ttvararray;
01118 
01119     //this loops through each variable and creates an array of useable varaibles' regexs
01120     foreach ($ttvararray AS $identifier => $ttvar)
01121     {
01122         $multiple = FALSE;
01123         foreach ($ttvar AS $key => $value)
01124         {
01125             //this checks if it's a multiply-defined variable
01126             if (is_numeric($key))
01127             {
01128                 $trigger_replaces = replace_vars($trigger_type, $ttvar[$key], $identifier, $param_array);
01129                 if (!empty($trigger_replaces))
01130                 {
01131                     $trigger_regex[] = $trigger_replaces['trigger_regex'];
01132                     $trigger_replace[] = $trigger_replaces ['trigger_replace'];
01133                 }
01134                 $multiple = TRUE;
01135             }
01136         }
01137         if ($multiple == FALSE)
01138         {
01139             $trigger_replaces = replace_vars($trigger_type, $ttvar, $identifier, $param_array);
01140 
01141             if (!empty($trigger_replaces))
01142             {
01143                 $trigger_regex[] = $trigger_replaces['trigger_regex'];
01144                 $trigger_replace[] = $trigger_replaces['trigger_replace'];
01145             }
01146         }
01147     }
01148     $string = preg_replace($trigger_regex, $trigger_replace, $string_array);
01149     return $string;
01150 }
01151 
01152 
01159 // function trigger_description($triggervar)
01160 // {
01161 //     global $CONFIG, $iconset;
01162 //     $html = ''.icon('trigger', 16)." ";
01163 //     $html .= "<strong>";
01164 //     if (!empty($triggervar['name'])) $html .= "{$triggervar['name']}";
01165 //     else $html .= "{$GLOBALS['strUnknown']}";
01166 //     $html .= "</strong><br />\n";
01167 //     if (isset($triggervar['description']))
01168 //     {
01169 //         $html .= $triggervar['description'];
01170 //     }
01171 //     else
01172 //     {
01173 //         $html .=  $triggervar['description'];
01174 //     }
01175 //     return $html;
01176 // }
01177 
01182 function trigger_types()
01183 {
01184     return $trigger_types;
01185 }
01186 
01187 
01194 function trigger_to_array($trigger)
01195 {
01196     $array['trigger_type'] = $trigger->getTrigger_type();
01197     $array['param_array'] = $trigger->getParam_array();
01198     $array['user_id'] = $trigger->getUser_id();
01199     $array['template'] = $trigger->getTemplate();
01200     $array['action'] = $trigger->getAction();
01201     $array['checks'] = $trigger->getChecks();
01202     $array['parameters'] = $trigger->getParameters();
01203 
01204     return $array;
01205 }
01206 
01207 
01215 function triggers_to_html($user_id, $trigger_id = '')
01216 {
01217     global $dbTriggers, $sit, $trigger_types, $strTrigger, $strActions;
01218 
01219     $user_id = cleanvar($user_id);
01220     if ($user_id == '') $user_id = $sit[2];
01221     $trigger_id = cleanvar($trigger_id);
01222 
01223     $html = "<table id='trigger_list'>";
01224     $html .= "<tr><th>{$strTrigger}</th><th>{$strActions}</th></tr>";
01225     $i = 0;
01226     foreach ($trigger_types AS $trigger => $description)
01227     {
01228         $trigger_html = trigger_to_html($trigger, $user_id);
01229         if (!empty($trigger_html))
01230         {
01231             $shade = ($i % 2) + 1;
01232             $html .= "<tr class='shade{$shade}'><td>".icon('trigger', 16);
01233             $html .= " ".$description['description']."</td><td><div class='triggeraction'>";
01234             $html .= $trigger_html;
01235             $html .= "</div></td></tr>";
01236             $i++;
01237         }
01238     }
01239     $html .= "</table>";
01240     return $html;
01241 }
01242 
01243 
01251 function trigger_to_html($trigger_id, $user_id)
01252 {
01253     global $dbTriggers;
01254     $html = '';
01255     $sql = "SELECT id FROM `{$dbTriggers}` ";
01256     $sql .= "WHERE userid = '{$user_id}' ";
01257     $sql .= "AND triggerid = '{$trigger_id}'";
01258     $result = mysql_query($sql);
01259     if (mysql_error())
01260     {
01261         trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
01262         trigger_error("Problem getting trigger details for {$trigger_id}");
01263         return FALSE;
01264     }
01265     if (mysql_num_rows($result) >= 0)
01266     {
01267         while ($row = mysql_fetch_object($result))
01268         {
01269             $t = Trigger::fromID($row->id);
01270             $html .= trigger_action_to_html($t);
01271         }
01272     }
01273 
01274     return $html;
01275 }
01276 
01277 
01284 function trigger_action_to_html($trigger)
01285 {
01286     global $trigger_types, $actionarray, $strChecks, $strParameters, $strMore, $strLess, $strEllipsis;
01287     $t_array = trigger_to_array($trigger);
01288     switch ($t_array['action'])
01289     {
01290         case 'ACTION_JOURNAL':
01291             $action = icon('configure', 16)." ";
01292             $action .= $GLOBALS['strLogTriggerInJournal'];
01293             break;
01294 
01295         case 'ACTION_NOTICE':
01296             $action = icon('info', 16)." ";
01297             $action .= $GLOBALS['strCreateANotice'];
01298             break;
01299 
01300         case 'ACTION_EMAIL':
01301             $action = icon('email', 16). " ";
01302             $action .= $GLOBALS['strSendAnEmail'];
01303             break;
01304 
01305         default:
01306             $action = $GLOBALS['strUnknown'];
01307             plugin_do('trigger_action_html');
01308         break;
01309     }
01310 
01311     $html .= $action;
01312 
01313     if (!empty($t_array['template']))
01314     {
01315         $html .= " <a href='templates.php?id={$t_array['template']}'>";
01316         $html .= "{$t_array['template']}</a> ";
01317         $desc = template_description($t_array['template'], $t_array['action']);
01318         if ($desc != '')
01319         {
01320             $html .= "<small>({$desc})</small><br />";
01321         }
01322     }
01323 
01324     if ($t_array['checks'] != '' OR $t_array['parameters'] != '')
01325     {
01326         $html .= "<span id='more_checks{$trigger->id}'>";
01327         $html .= "<a href='javascript:void(0)' ";
01328         $html .= "onclick=\"javascript:$('checksandparams{$trigger->id}').show(); $('less_checks{$trigger->id}').show(); $('more_checks{$trigger->id}').hide()\">";
01329         $html .= icon('auto', 16) ." {$strMore}{$strEllipsis}</a></span> ";
01330 
01331         $html .= "<span id='less_checks{$trigger->id}' style='display:none'>";
01332         $html .= "<a href='javascript:void(0)' ";
01333         $html .= "onclick=\"javascript:$('checksandparams{$trigger->id}').hide(); $('less_checks{$trigger->id}').hide(); $('more_checks{$trigger->id}').show()\">";
01334         $html .= icon('auto', 16) ." {$strLess}{$strEllipsis}</a></span> ";
01335 
01336         $html .= "<span id='checksandparams{$trigger->id}' style='display:none'>";
01337         if ($t_array['checks'] != '')
01338         {
01339             $html .= "<strong>{$strChecks}</strong>: ";
01340             //FIXME 4.0
01341             //$html .= checks_to_html($t_array['checks'])." ".help_link('trigger_checks')." ";
01342             $html .= $t_array['checks']." ".help_link('trigger_checks')." ";
01343 
01344         }
01345         if ($t_array['parameters'] != '')
01346         {
01347             // FIXME i18n
01348             $html .= "<strong>Parameters</strong>: {$t_array['parameters']} ".help_link('trigger_parameters')." ";
01349         }
01350         $html .= "</span>";
01351     }
01352 
01353     $html .=  "<div class='triggeractions'>";
01354     $operations = array();
01355     // FIXME 3.90, add edit back in
01356     // $operations[$GLOBALS['strEdit']] = "action_details.php?id={$trigger->id}";
01357     $operations[$GLOBALS['strDelete']] = "action_details.php?action=delete&amp;id={$trigger->id}";
01358     $html .= html_action_links($operations);
01359     $html .= "</div><br />";
01360     return $html;
01361 }
01362 
01363 
01371 function template_description($name, $type)
01372 {
01373     global $dbEmailTemplates, $dbNoticeTemplates;
01374     $name = cleanvar($name);
01375     if ($type == 'ACTION_NOTICE')
01376     {
01377         $tbl = $dbNoticeTemplates;
01378     }
01379     elseif ($type == 'ACTION_EMAIL')
01380     {
01381         $tbl = $dbEmailTemplates;
01382     }
01383     $sql = "SELECT description FROM `{$tbl}` WHERE name = '{$name}'";
01384     $result = mysql_query($sql);
01385     list($desc) = mysql_fetch_row($result);
01386     (substr_compare($desc, "str", 1, 3)) ? $desc = $GLOBALS[$desc] : $desc;
01387     if ($desc == '') $desc = FALSE;
01388     return $desc;
01389 }
01390 
01391 
01397 function check_match_drop_down($id = '')
01398 {
01399     $html = "<select id='{$id}' name='{$id}'>";
01400     $html .= "<option value='is'>{$GLOBALS['strIs']}</option>";
01401     $html .= "<option value='is not'>{$GLOBALS['strIsNot']}</option>";
01402     $html .= "<option value='contains'>{$GLOBALS['strContains']}</option>";
01403     $html .= "<option value='does not contain'>{$GLOBALS['strDoesNotContain']}</option>";
01404     $html .= "</select>";
01405 
01406     return $html;
01407 }
01408 
01409 
01418 function create_check_string($param, $value, $join, $enabled, $conditions)
01419 {
01420     $param_count = sizeof($param);
01421 
01422     for ($i = 0; $i < $param_count; $i++)
01423     {
01424         if ($enabled[$i] == 'on')
01425         {
01426             $checks[$i] = "{".$param[$i]."}";
01427             if ($join[$i] == 'is') $checks[$i] .= "==";
01428             elseif ($join[$i] == 'is not') $checks[$i] .= "!=";
01429             elseif ($join[$i] == 'contains') trigger_error("Contains not yet supported");
01430             elseif ($join[$i] == 'does not contain') trigger_error("Contains not yet supported");
01431             $checks[$i] .= $value[$i];
01432         }
01433     }
01434 
01435     $check_count = sizeof($checks);
01436     if ($check_count > 0)
01437     {
01438         foreach ($checks as $key => $value)
01439         {
01440             $final_check .= $checks[$key];
01441             if ($check_count != 1)
01442             {
01443                 if ($conditions == 'all')
01444                 {
01445                     $final_check .= " AND ";
01446                 }
01447                 else
01448                 {
01449                     $final_check .= " OR ";
01450                 }
01451             }
01452             $check_count --;
01453         }
01454     }
01455 
01456     return $final_check;
01457 }
01458 
01459 
01467 function checks_to_html($checks)
01468 {
01469     $checks = trim($checks);
01470     if ($checks != '')
01471     {
01472         if (strpos($checks, 'AND') !== FALSE)
01473         {
01474             $checks = explode('AND', $checks);
01475         }
01476         elseif (strpos($checks, 'OR') !== FALSE)
01477         {
01478             $checks = explode('OR', $checks);
01479         }
01480         else
01481         {
01482             $checks[0] = $checks;
01483         }
01484         $html = "";
01485         foreach ($checks as $check)
01486         {
01487             $original_check = $check;
01488             if (strpos($check, '==') !== FALSE)
01489             {
01490                 $check = explode('==', $check);
01491                 $check[0] = trim($check[0]);
01492                 $check[1] = trim($check[1]);
01493             }
01494             elseif (strpos($check, '!=') !== FALSE)
01495             {
01496                 $check = explode('!=', $check);
01497                 $check[0] = trim($check[0]);
01498                 $check[1] = trim($check[1]);
01499             }
01500             else
01501             {
01502                 trigger_error('not yet supported', E_USER_ERROR);
01503                 $html .= $original_check;
01504             }
01505 
01506             if ($ttvararray[$check[0]]['checkreplace'] != '')
01507             {
01508                 $html .= $ttvararray[$check[0]]['checkreplace']();
01509             }
01510             else
01511             {
01512                 $html .= $original_check;
01513             }
01514         }
01515     }
01516     return $html;
01517 }
01518 
01523 function freeform($name)
01524 {
01525     $html = "<input name='name' />";
01526     return $html;
01527 }
01528 
01533 function trigger($trigger_id, $param_array)
01534 {
01535     trigger_error("trigger() is deprecated, please use the TriggerEvent class instead", E_USER_DEPRECATED);
01536     new TriggerEvent($trigger_id, $param_array);
01537 }
01538 ?>