function submitAdd()
 {
     global $dcl_info, $g_oSec;
     // We actually have to potentially add several things here for a new org
     commonHeader();
     if (!$g_oSec->HasPerm(DCL_ENTITY_ORG, DCL_PERM_ADD)) {
         return PrintPermissionDenied();
     }
     CleanArray($_REQUEST);
     $obj = CreateObject('dcl.boOrg');
     $oOrgID = $obj->add(array('name' => $_REQUEST['name'], 'active' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     if ($oOrgID == -1) {
         // TODO: redisplay in case it can be resubmitted
         $this->ShowEntryForm();
         return;
     }
     $aOrgTypes = @DCL_Sanitize::ToIntArray($_REQUEST['org_type_id']);
     if ($aOrgTypes !== null) {
         $oOrgTypeXref =& CreateObject('dcl.boOrgTypeXref');
         $oOrgTypeXref->PermAdd = DCL_PERM_ADD;
         foreach ($aOrgTypes as $iTypeID) {
             $oOrgTypeXref->add(array('org_id' => $oOrgID, 'org_type_id' => $iTypeID));
         }
     }
     // All of these are info in other tables, but they use the permissions of the org entity
     // So, we need to temporarily set the PermAdd to DCL_PERM_ADD so these will succeed.
     if ($_REQUEST['alias'] != '') {
         $oOrgAlias = CreateObject('dcl.boOrgAlias');
         $oOrgAlias->PermAdd = DCL_PERM_ADD;
         $oOrgAlias->add(array('org_id' => $oOrgID, 'alias' => $_POST['alias'], 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $addr_type_id = DCL_Sanitize::ToInt($_REQUEST['addr_type_id']);
     if ($addr_type_id > 0) {
         $oOrgAddr = CreateObject('dcl.boOrgAddr');
         $oOrgAddr->PermAdd = DCL_PERM_ADD;
         $oOrgAddr->add(array('org_id' => $oOrgID, 'addr_type_id' => $addr_type_id, 'add1' => $_REQUEST['add1'], 'add2' => $_REQUEST['add2'], 'city' => $_REQUEST['city'], 'state' => $_REQUEST['state'], 'zip' => $_REQUEST['zip'], 'country' => $_REQUEST['country'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $phone_type_id = DCL_Sanitize::ToInt($_REQUEST['phone_type_id']);
     if ($_POST['phone_type_id'] > 0 && $_POST['phone_number'] != '') {
         $oOrgPhone = CreateObject('dcl.boOrgPhone');
         $oOrgPhone->PermAdd = DCL_PERM_ADD;
         $oOrgPhone->add(array('org_id' => $oOrgID, 'phone_type_id' => $phone_type_id, 'phone_number' => $_REQUEST['phone_number'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $email_type_id = DCL_Sanitize::ToInt($_REQUEST['email_type_id']);
     if ($_POST['email_type_id'] > 0 && $_POST['email_addr'] != '') {
         $oOrgEmail = CreateObject('dcl.boOrgEmail');
         $oOrgEmail->PermAdd = DCL_PERM_ADD;
         $oOrgEmail->add(array('org_id' => $oOrgID, 'email_type_id' => $email_type_id, 'email_addr' => $_REQUEST['email_addr'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $url_type_id = DCL_Sanitize::ToInt($_REQUEST['url_type_id']);
     if ($_POST['url_type_id'] > 0 && $_POST['url_addr'] != '') {
         $oOrgUrl = CreateObject('dcl.boOrgUrl');
         $oOrgUrl->PermAdd = DCL_PERM_ADD;
         $oOrgUrl->add(array('org_id' => $oOrgID, 'url_type_id' => $url_type_id, 'url_addr' => $_REQUEST['url_addr'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     if (EvaluateReturnTo()) {
         return;
     }
     $_REQUEST['org_id'] = $oOrgID;
     $oOrg =& CreateObject('dcl.htmlOrgDetail');
     $oOrg->show();
 }
 function submitDelete()
 {
     global $dcl_info, $g_oSec;
     commonHeader();
     if (!$g_oSec->HasPerm(DCL_ENTITY_RESOLUTION, DCL_PERM_DELETE)) {
         return PrintPermissionDenied();
     }
     if (($id = DCL_Sanitize::ToInt($_REQUEST['resid'])) === null) {
         trigger_error('Data sanitize failed.');
         return;
     }
     $oResolution = CreateObject('dcl.dbTicketresolutions');
     if ($oResolution->Load($id) == -1) {
         return;
     }
     $iTicketID = $oResolution->ticketid;
     $oBO = CreateObject('dcl.boTicketresolutions');
     $aKey = array('resid' => $id, 'ticketid' => $iTicketID);
     $oBO->delete($aKey);
     if (EvaluateReturnTo()) {
         return;
     }
     $oTicket =& CreateObject('dcl.dbTickets');
     if ($oTicket->Load($iTicketID) == -1) {
         return -1;
     }
     $objH = CreateObject('dcl.htmlTicketDetail');
     $objH->Show($oTicket);
 }
 function submitAdd()
 {
     global $dcl_info, $g_oSec;
     // We actually have to potentially add several things here for a new contact
     commonHeader();
     if (!$g_oSec->HasPerm(DCL_ENTITY_CONTACT, DCL_PERM_ADD)) {
         return PrintPermissionDenied();
     }
     CleanArray($_REQUEST);
     $obj = CreateObject('dcl.boContact');
     $iContactID = $obj->add(array('first_name' => $_REQUEST['first_name'], 'middle_name' => $_REQUEST['middle_name'], 'last_name' => $_REQUEST['last_name'], 'active' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     if ($iContactID == -1) {
         // TODO: redisplay in case it can be resubmitted
         $this->ShowEntryForm();
         return;
     }
     $aContactTypes = @DCL_Sanitize::ToIntArray($_REQUEST['contact_type_id']);
     if ($aContactTypes !== null) {
         $oContactTypeXref =& CreateObject('dcl.boContactTypeXref');
         $oContactTypeXref->PermAdd = DCL_PERM_ADD;
         foreach ($aContactTypes as $iTypeID) {
             $oContactTypeXref->add(array('contact_id' => $iContactID, 'contact_type_id' => $iTypeID));
         }
     }
     $org_id = DCL_Sanitize::ToInt($_REQUEST['org_id']);
     if ($org_id > 0) {
         $oOrgContact = CreateObject('dcl.boOrgContact');
         $oOrgContact->add(array('org_id' => $org_id, 'contact_id' => $iContactID, 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $addr_type_id = DCL_Sanitize::ToInt($_REQUEST['addr_type_id']);
     if ($addr_type_id > 0) {
         $oContactAddr = CreateObject('dcl.boContactAddr');
         $oContactAddr->add(array('contact_id' => $iContactID, 'addr_type_id' => $addr_type_id, 'add1' => $_REQUEST['add1'], 'add2' => $_REQUEST['add2'], 'city' => $_REQUEST['city'], 'state' => $_REQUEST['state'], 'zip' => $_REQUEST['zip'], 'country' => $_REQUEST['country'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $phone_type_id = DCL_Sanitize::ToInt($_REQUEST['phone_type_id']);
     if ($phone_type_id > 0 && $_REQUEST['phone_number'] != '') {
         $oContactPhone = CreateObject('dcl.boContactPhone');
         $oContactPhone->add(array('contact_id' => $iContactID, 'phone_type_id' => $phone_type_id, 'phone_number' => $_REQUEST['phone_number'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $email_type_id = DCL_Sanitize::ToInt($_REQUEST['email_type_id']);
     if ($email_type_id > 0 && $_REQUEST['email_addr'] != '') {
         $oContactEmail = CreateObject('dcl.boContactEmail');
         $oContactEmail->add(array('contact_id' => $iContactID, 'email_type_id' => $email_type_id, 'email_addr' => $_REQUEST['email_addr'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     $url_type_id = DCL_Sanitize::ToInt($_REQUEST['url_type_id']);
     if ($_POST['url_type_id'] > 0 && $_REQUEST['url_addr'] != '') {
         $oContactUrl = CreateObject('dcl.boContactUrl');
         $oContactUrl->add(array('contact_id' => $iContactID, 'url_type_id' => $url_type_id, 'url_addr' => $_REQUEST['url_addr'], 'preferred' => 'Y', 'created_on' => DCL_NOW, 'created_by' => $GLOBALS['DCLID']));
     }
     if (isset($_REQUEST['fromBrowse']) && $_REQUEST['fromBrowse'] == 'true') {
         $_REQUEST['return_to'] = 'menuAction=htmlContactSelector.showBrowseFrame&filterActive=S&filterID=' . $iContactID . '&updateTop=true';
     }
     if (EvaluateReturnTo()) {
         return;
     }
     $this->ShowEntryForm();
 }
 function dbbatchassign()
 {
     global $dcl_info, $g_oSec;
     commonHeader();
     if (!$g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_ASSIGN)) {
         return PrintPermissionDenied();
     }
     if (isset($_REQUEST['selected']) && is_array($_REQUEST['selected']) && count($_REQUEST['selected']) > 0) {
         $objWtch =& CreateObject('dcl.boWatches');
         $objWO =& CreateObject('dcl.dbWorkorders');
         $bNeedBreak = false;
         if (($iResponsible = @DCL_Sanitize::ToInt($_REQUEST['responsible'])) === null) {
             trigger_error('Data sanitize failed.');
             return;
         }
         if (($iPriority = @DCL_Sanitize::ToInt($_REQUEST['priority'])) === null) {
             $iPriority = 0;
         }
         if (($iSeverity = @DCL_Sanitize::ToInt($_REQUEST['severity'])) === null) {
             $iSeverity = 0;
         }
         foreach ($_REQUEST['selected'] as $val) {
             list($jcn, $seq) = explode('.', $val);
             if (($jcn = DCL_Sanitize::ToInt($jcn)) === null || ($seq = DCL_Sanitize::ToInt($seq)) === null) {
                 trigger_error('Data sanitize failed.');
                 return;
             }
             if ($objWO->Load($jcn, $seq) == -1) {
                 continue;
             }
             if ($objWO->responsible != $iResponsible || $iPriority > 0 && $objWO->priority != $iPriority || $iSeverity > 0 && $objWO->severity != $iSeverity) {
                 $objWO->responsible = $iResponsible;
                 if ($iPriority > 0) {
                     $objWO->priority = $iPriority;
                 }
                 if ($iSeverity > 0) {
                     $objWO->severity = $iSeverity;
                 }
                 $objWO->Edit();
                 $objWtch->sendNotification($objWO, '4,1');
             }
         }
     }
     if (EvaluateReturnTo()) {
         return;
     }
     $objView =& CreateObject('dcl.boView');
     $objView->SetFromURL();
     $objH =& CreateObject('dcl.htmlWorkOrderResults');
     $objH->Render($objView);
 }
 function dbbatchadd()
 {
     global $g_oSec;
     commonHeader();
     if (!$g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_ACTION)) {
         PrintPermissionDenied();
         return EvaluateReturnTo();
     }
     $objTimecard =& CreateObject('dcl.dbTimeCards');
     $objTimecard->InitFromGlobals();
     $objTimecard->actionby = $GLOBALS['DCLID'];
     if ($g_oSec->IsPublicUser()) {
         $objTimecard->is_public = 'Y';
     } else {
         $objTimecard->is_public = @DCL_Sanitize::ToYN($_REQUEST['is_public']);
     }
     if (($targeted_version_id = @DCL_Sanitize::ToInt($_REQUEST['targeted_version_id'])) === null) {
         $targeted_version_id = 0;
     }
     if (($fixed_version_id = @DCL_Sanitize::ToInt($_REQUEST['fixed_version_id'])) === null) {
         $fixed_version_id = 0;
     }
     $objWorkorder =& CreateObject('dcl.dbWorkorders');
     $objWtch =& CreateObject('dcl.boWatches');
     if (isset($_REQUEST['selected']) && is_array($_REQUEST['selected']) && count($_REQUEST['selected']) > 0) {
         $bProcessTags = isset($_REQUEST['tags']) && trim($_REQUEST['tags']) != '' && $g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_MODIFY);
         $oTag =& CreateObject('dcl.dbEntityTag');
         $bProcessHotlist = isset($_REQUEST['hotlist']) && trim($_REQUEST['hotlist']) != '' && $g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_MODIFY);
         $oHotlist =& CreateObject('dcl.dbEntityHotlist');
         foreach ($_REQUEST['selected'] as $key => $val) {
             list($objTimecard->jcn, $objTimecard->seq) = explode('.', $val);
             $objTimecard->jcn = DCL_Sanitize::ToInt($objTimecard->jcn);
             $objTimecard->seq = DCL_Sanitize::ToInt($objTimecard->seq);
             if ($objTimecard->jcn === null || $objTimecard->seq === null) {
                 continue;
             }
             if ($objWorkorder->Load($objTimecard->jcn, $objTimecard->seq) == -1) {
                 continue;
             }
             $status = $objWorkorder->status;
             $objTimecard->Add($targeted_version_id, $fixed_version_id);
             // * Tags
             if ($bProcessTags) {
                 $oTag->serialize(DCL_ENTITY_WORKORDER, $objTimecard->jcn, $objTimecard->seq, $_REQUEST['tags'], true);
             }
             // * Hotlists
             if ($bProcessHotlist) {
                 $oHotlist->serialize(DCL_ENTITY_WORKORDER, $objTimecard->jcn, $objTimecard->seq, $_REQUEST['hotlist'], true);
             }
             $notify = '4';
             if ($status != $objTimecard->status) {
                 $notify .= ',3';
                 $oStatus =& CreateObject('dcl.dbStatuses');
                 if ($oStatus->GetStatusType($objTimecard->status) == 2) {
                     $notify .= ',2';
                     // also need to close all incomplete tasks and warn user if it happens
                     $this->closeIncompleteTasks($objTimecard->jcn, $objTimecard->seq);
                 } else {
                     if ($oStatus->GetStatusType($objTimecard->status) == 1) {
                         $notify .= ',1';
                     }
                 }
             }
             // Reload before sending since time card modifies the work order
             if ($objWorkorder->Load($objTimecard->jcn, $objTimecard->seq) != -1) {
                 $objWtch->sendNotification($objWorkorder, $notify, false);
             }
         }
     }
     if (EvaluateReturnTo()) {
         return;
     }
     $objView =& CreateObject('dcl.boView');
     $objView->SetFromURL();
     $objH =& CreateObject('dcl.htmlWorkOrderResults');
     $objH->Render($objView);
 }