Documentation is available at contract.php
- <?php
- /**
- * @package helpdesk
- * Copyright OSI 2005. All rights reserved.
- * It is expected that version 1.0 will be GPLed, but this interim work
- * is kept closed until 1.0 is ready.
- */
- $_contract_saved_er = error_reporting(E_ALL || E_STRICT) ;
- /**
- * import ancillary functions
- */
- require_once("misc.php");
- /**
- * import HD core
- */
- require_once("core.php");
- /**
- * Support contract
- * @package helpdesk
- */
- class helpdeskContract extends helpdeskObject
- {
- public $node ; ///< backlink to drupal node object
- public $defTimeIncrement; // default increment for elapsed time on timed contracts
- public $isSuspended; // is contract currently in suspended mode ?
- public $maxDate; // maximum date for which this contract is valid
- public $maxIssue;// maximum number of issues for which this contract is valid
- public $maxTime; // maximum elapsed time for which this contract is valid
- public $timeId; // time information for this contract
- public $uidCustomer; // owner of contract
- public $useMaxDate; // use the $maxDate parameter
- public $useMaxIssue;// use the $maxIssue parameter
- public $useMaxTime; // use the $maxTime parameter
- /**
- * Constructor-like method filling node from set of data in node
- * If nid is NULL, the node is new and nothing can be filled.
- * @param object $node
- * @todo consider the issues surrounding timeId from initial submission to actual insert
- */
- function init($node, $fromDB)
- {
- if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
- { echo "<pre>HD CONTRACT/init (" . (isset($node->nid) ? $node->nid : 'new node') . ")</pre>\r\n" ; }
- $this->node = $node ;
- /**
- * node == NULL: can it happen ?
- * !is_object($node): can it happen ?
- * !isset($node->nid): new node before insert (doing preview)
- * full node, but not in DB: new node before insert (initialising for insert)
- */
- if (!$fromDB)
- {
- // This is a new node, we initialize the object from the variable, there's nothing in the DB
- foreach ($this as $key => $value)
- {
- if (($key <> 'node') && ($key <> 'timeId')) // node: Don't recurse, timeId: must think more deeply about it
- $this->$key = isset($node->$key) ? $node->$key : NULL ;
- }
- return;
- }
- else
- {
- $q = '
- SELECT
- hdc.defTimeIncrement, hdc.isSuspended,
- hdc.timeId, hdc.uidCustomer,
- hdc.maxDate, hdc.maxIssue, hdc.maxTime,
- hdc.useMaxDate, hdc.useMaxIssue, hdc.useMaxTime,
- hdt.stime, hdt.atime, hdt.mtime, hdt.etime
- FROM
- {hd_contract} hdc
- LEFT JOIN {hd_timeinfo} hdt on hdc.timeid = hdt.timeid
- WHERE
- hdc.nid = %d' ;
- $res = db_query($q, $node->nid);
- $ar = db_fetch_array($res) ; // Should give exactly one row of result, zero if contract does not exist yet
- foreach ($ar as $key => $value)
- {
- $this->$key = $value ;
- }
- // echo "<pre>New contract object: " ; print_r ($this) ; "</pre>\r\n";
- }
- }
- /**
- * implement hook_view for HD contracts
- * @todo implement display of the timeinfo object
- * @todo implement contract balance display
- * @return string
- *
- */
- function view()
- {
- $headers = array(
- t('Attribute'),
- t('Use'),
- t('Maximum'),
- t('Current')
- ) ;
- $rows = array
- ( // Row with attributes on the row and some of its cells.
- array // First row
- (
- t('Number of issues'),
- array ('data' => $this->useMaxIssue ? t('Yes') : t('No'), 'style' => 'text-align: center'),
- array ('data' => _helpdesk_notempty($this->maxIssue, '0'), 'style' => 'text-align: center'),
- HELPDESKUNIMPLEMENTED
- ),
- array // First row
- (
- t('Date'),
- array ('data' => $this->useMaxDate ? t('Yes') : t('No'), 'style' => 'text-align: center'),
- array ('data' => format_date($this->maxDate, 'medium'), 'style' => 'text-align: center'),
- HELPDESKUNIMPLEMENTED
- ),
- array // First row
- (
- t('Spent minutes'),
- array ('data' => $this->useMaxTime ? t('Yes') : t('No'), 'style' => 'text-align: center'),
- array ('data' => _helpdesk_notempty($this->maxTime, '0'), 'style' => 'text-align: center'),
- HELPDESKUNIMPLEMENTED
- ),
- );
- $output = theme_table($headers, $rows);
- $ar = array();
- $custname = user_load(array('uid' => $this->uidCustomer))->name;
- $ar[] = sprintf (t('Contract holder: %s'), l($custname, 'user/' . $this->uidCustomer)) ;
- unset($custname);
- $ar[] = sprintf(t('Default time increment for events, in minutes: %d '), _helpdesk_notempty($this->defTimeIncrement, '0'));
- $ar[] = sprintf(t('Is contract suspended ? %s'), $this->isSuspended ? t('Yes') : t('No'));
- $output .= theme_item_list($ar);
- return $output;
- }
- /**
- * Implement hook_insert for HD Contracts
- *
- * @return void
- */
- function insert()
- {
- /* all of this must be inserted
- public $node ; ///< backlink to drupal node object
- public $defTimeIncrement; // default increment for elapsed time on timed contracts
- public $isSuspended; // is contract currently in suspended mode ?
- public $maxDate; // maximum date for which this contract is valid
- public $maxIssue;// maximum number of issues for which this contract is valid
- public $maxTime; // maximum elapsed time for which this contract is valid
- public $timeId; // time information for this contract
- public $uidCustomer; // owner of contract
- public $useMaxDate; // use the $maxDate parameter
- public $useMaxIssue;// use the $maxIssue parameter
- public $useMaxTime; // use the $maxTime parameter */
- $q = '
- INSERT INTO {hd_contract}
- (deftimeincrement, issuspended,
- maxdate, maxissue, maxtime,
- nid, timeid, uidcustomer,
- usemaxdate, usemaxissue, usemaxtime)
- VALUES
- (%d, %d,
- %d, %d, %d,
- %d, %d, %d,
- %d, %d, %d)
- ';
- $res = db_query($q,
- $this->defTimeIncrement, $this->isSuspended,
- $this->maxDate, $this->maxIssue, $this->maxTime,
- $this->node->nid, $this->timeId, $this->uidCustomer,
- $this->useMaxDate, $this->useMaxIssue, $this->useMaxTime
- );
- }
- /**
- *
- * @param helpdeskCustomer $uidcustomer
- * @desc lists contracts held by a helpdeskCustomer
- * @return array contract summaries (nid, title, created, changed) orderd by nid
- */
- static function getContractsByUid (helpdeskCustomer $uidcustomer)
- {
- $q = '
- select
- n.nid, n.title, n.created, n.changed
- from
- hd_contract hdc
- left join node n on hdc.nid = n.nid
- where UIDCUSTOMER = %d
- order by
- 1
- ' ;
- $ret = array () ;
- $res = db_query ($q, $uidcustomer) ;
- while ($o = db_fetch_object($res))
- {
- $ret[] = array();
- $ret[]['nid'] = $o->nid ;
- $ret[]['title'] = $o->title ;
- $ret[]['created'] = $o->created ;
- $ret[]['changed'] = $o->changed ;
- }
- return $ret ;
- }
- /**
- * @return array
- * @desc Returns the nids of all tickets bound to this contracts
- */
- function getTickets ()
- {
- $ret = array() ;
- $sq = 'select distinct NID from {hd_event} ev '
- . 'inner join {hd_timeinfo} ti on ev.TIMEID = ti.TIMEID '
- . 'where '
- . ' (NIDROOT = NID) ' // This only matches tickets, not other events
- . ' and (CONTRACTID=%1) '
- . 'order by ti.TIMEID desc ' ;
- $q = db_query($sq, $this->nid) ;
- while ($o = db_result($q))
- {
- array_push ($o) ;
- }
- unset ($o) ;
- unset ($q) ;
- unset ($sq) ;
- return $ret ;
- }
- /**
- * Generates the code for hook_form when node is a helpdesk Contract
- * @return string HTML
- */
- function form()
- {
- // Now we define the form elements specific to our node type.
- if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
- {
- $ret = t ("<p>Defining new %nodename</p>\n", array ('%nodename' => $this->node_name())) ;
- }
- else
- $ret = '' ;
- /* This would allow format selection, but contracts are plain text, so we use 1 = filtered html */
- // $ret .= filter_form ('format', $node->format);
- // $node->format = 1 ; // Filtered HTML
- // But there's no "node" code in this method !
- // @todo find where input filtering goes in this model
- // Select contract holder
- $q = '
- select
- distinct hdu.uidcustomer,
- u.name
- from
- {hd_user} hdu
- left join {users} u on hdu.uidcustomer = u.uid
- order by
- 1
- ' ;
- $res = db_query($q);
- $arCustomers = array() ;
- while ($o = db_fetch_object($res))
- $arCustomers[$o->uidcustomer] = "$o->name ($o->uidcustomer)" ; // We do this in code instead of SQL because SQL concatenation is not portable
- $ret = form_select('Contract holder', 'uidCustomer', $this->uidCustomer, $arCustomers,
- t('Choose the customer holding this contract.'), NULL,
- FALSE, // Only one customer per contract
- TRUE);
- /* display contract timeinfo */
- $ti = new helpdeskTimeInfo();
- $ti->init(array(
- 'S' => time(),
- 'A' => time(),
- 'M' => time(),
- 'E' => '',
- 'showS' => TRUE, 'showA' => TRUE, 'showM' => TRUE, 'showE' => TRUE,
- 'enabledS' => TRUE, 'enabledA' => FALSE, 'enabledM' => FALSE, 'enabledE' => TRUE),
- FALSE) ; // Load from params, not from DB
- $items = $ti->form();
- $ret .= form_group
- (
- t ('Contract date information'),
- $items,
- t ('Here you must define the date the contract starts (default to current date) and can optionally define when it ends'
- // . ', and access/modification dates (default to current date)'
- ),
- NULL) ;
- /**
- * Parameters for new contract
- */
- $items = form_checkbox (t ('Suspended'), 'isSuspended', 1, $this->isSuspended, '', NULL, FALSE) ;
- $items .= theme_table
- (
- array (t ('Contract limits'), t ('Limit value'), t ('Increment')),
- array
- (
- array (
- form_checkbox (t ('Minutes spent'), 'useMaxTime', 1, $this->useMaxTime, '', NULL, FALSE),
- form_textfield ('', 'maxTime', $this->maxTime, 16, 16, NULL, NULL, FALSE),
- form_textfield ('', 'defTimeIncrement', $this->defTimeIncrement, 4, 4, NULL, NULL, FALSE)
- ),
- array (
- form_checkbox (t ('Number of tickets'), 'useMaxIssue', 1, $this->useMaxIssue, '', NULL, FALSE),
- form_textfield ('', 'maxIssue', $this->maxIssue, 16, 16, NULL, NULL, FALSE),
- ' '),
- array (
- form_checkbox (t ('Date'), 'useMaxDate', 1, $this->useMaxDate, '', NULL, FALSE),
- form_textfield ('', 'maxDate', $this->maxDate, 16, 16, NULL, NULL, FALSE),
- ' ')
- )
- ) ;
- $ret .= form_group (
- t ('Contract status'),
- $items,
- t ('Here you set the attributes of the contract: is it time-limited, duration-limited, issue-limited ? does it start suspended ?'
- . ' The increment value for time-limited contracts is the default duration consumed by each followup.'),
- NULL) ;
- $ret .= form_textarea(t('Contract wording'), 'body', (isset($this->node->body) ? $this->node->body : ''), 60, 20);
- return $ret ;
- }
- }
- error_reporting($_contract_saved_er) ;
- unset($_contract_saved_er) ;
- ?>
Documentation generated on Tue, 01 Nov 2005 23:14:58 +0100 by phpDocumentor 1.3.0RC3