//print_r($_GET);
if(!isset($_GET['mac']))
{
$modx->log(modX::LOG_LEVEL_ERROR," no mac found");
return;
}
//$modx->log(modX::LOG_LEVEL_ERROR,implode(",",$_GET));
$c = $modx->newQuery('modUser');
// $c->select($this->xpdo->getSelectColumns('modUser','modUser'));
$c->select('id');
$collection=$modx->getCollection('modUser',$c);
$arr2=array();
foreach($collection as $item)
{
$arr2=$item->toArray();
$id=$arr2['id'];
//print_r($arr);
$c1=$modx->newQuery('modUserProfile');
$c1->where(array('id'=>$id));
$collection2=$modx->getCollection('modUserProfile',$c1);
foreach($collection2 as $item2)
{
$arr=$item2->toArray();
//print_r($arr);
//$id=$arr['id'];
$rem="1";
$rem2=$arr['extended']['ReportEmail'];
if($rem!=$rem2)
continue;
//endif;
if(isset($arr['extended']) && isset($arr['extended']['mac'])):
$tmac=$arr['extended']['mac'];
if($tmac!=$_GET['mac'])
continue;
$replace=array('address'=>$arr['address'],
'company'=>$arr['extended']['company'],
'zone_id'=>$_GET['zone_id'],
'zone_desc'=>$_GET['zone_desc'],
'account_code'=>$_GET['account_code'],
'date'=>date('d M y - g:i A', strtotime($_GET['time'])),
'event_code'=>$_GET['event_code'],
'event_group'=>$_GET['event_group'],
'mac'=>$arr['extended']['mac'],
'raw_data'=>$_GET['raw_data'],
'id2'=>$_GET['id2'],
'alarm_reason'=>$_GET['alarm_reason'],
'event_desc'=>$_GET['event_desc'],
'event_alt'=>$_GET['event_alt'],
'event_state'=>$_GET['event_state'],
'user_desc'=>$_GET['user_desc'],
'name'=>$arr['fullname'],
'id'=>$arr['id'],
'idM'=>$arr['extended']['userID'],
'sACC'=>$arr['extended']['tick']['sACC'],
'mCom'=>$arr['extended']['MONcompany'],
'mPh'=>$arr['extended']['MONphone'],
'mEx'=>$arr['extended']['tick']['MONexternal'],
'reportE'=>$arr['extended']['ReportEmail'],
);
[[!UpdateProfile? &useExtended=`1`]]
<form class="form" action="[[~[[*id]]]]" method="post"><input type="hidden" name="nospam:blank" value="" />
<input type="text" name="602Time" id="602Time" value="$_GET['time']" />
$chunk=$modx->getChunk('mailchunk',$replace);
//sending mail
$message = $modx->getChunk('myEmailTemplate');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$chunk);
$from=(isset($from))?$from:'[email protected]';
$fname=isset($fname)?$fname:'Alarm Server';
if(isset($_GET['alarm_reason']) )
$subject='Alarm Trigger: '.$_GET['alarm_reason'];
else
$subject='Alarm Trigger';
$modx->mail->set(modMail::MAIL_FROM,$from);
$modx->mail->set(modMail::MAIL_FROM_NAME,$fname);
$modx->mail->set(modMail::MAIL_SUBJECT,$subject);
$modx->mail->address('to',$arr['email']);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
///
endif;
}//loop2
}//loop1if(!isset($_GET['mac'])) {
$modx->log(modX::LOG_LEVEL_ERROR," no mac found");
return;
} else {
$mac = $_GET['mac'];
}
$c = $modx->newQuery('modUserProfile');
$c->where(array('fax' => $mac));
$profile = $modx->getObject('modUserProfile', $c);
if ($profile) {
$modx->log(modX::LOG_LEVEL_ERROR," User Profile not found");
return;
}
$extended = $profile->get('extended');
/* You only need to set the ones that are being updatad here */
$extended['zone_id'] = $_GET['zone_id'];
$extended['zone_desc']= $_GET['zone_desc'];
$extended['account_code']= $_GET['account_code'];
$extended['date']= date('d M y - g:i A', strtotime($_GET['time']));
$extended['602time'] = $_GET['time'];
// etc.
$profile->set('extended', $extended);
$profile->save();
/* email code here */
$userDataObject = $modx->getObject('userData', array('mac' => $_GET['mac']));
if ($userDataObject) {
$userDataObject->set('zone_id', $_GET['zone_id']);
$userDataObject->set('zone_desc',$_GET['zone_desc']);
$userDataObject->set('account_code',$_GET['account_code']);
$userDataObject->set('date', date('d M y - g:i A', strtotime($_GET['time'])));
$userDataObject->set('602time',$_GET['time']);
$userDataObject->save();
}
/* Email code here */
<?php
/* SCRIPT UPDATE
As suggested by BOB RAY to use classExtender instead of the Extended Fields to speed up script
https://forums.modx.com/thread/97912/updated-user-extended-fields-in-snippet-from-curl-call#dis-post-529455
DATE: 05-08-2015
VERSION: 1.0
*/
$userDataObject = $modx->getObject('userData', array('mac' => $_GET['mac']));
if ($userDataObject) {
$userDataObject->set('fullname',$_GET['fullname']);
$userDataObject->set('company',$_GET['company']);
$userDataObject->set('id',$_GET['id']);
$userDataObject->set('account_code',$_GET['account_code']);
$userDataObject->set('602time',$_GET['time']);
$userDataObject->save();
}
$rem="1";
$rem2 = $modx->getObject('userData', array('ReportEmail'));
if($rem!=$rem2)
continue;
/* information received from CURL
SAMPLE:
http://URL/trigger.html?s=1&account_code=9876&event_code=602&mac=000&raw_data=9876&event_desc=Ne&event_alt=Op&event_state=Di&zone_id=00&zone_desc=&partition=00&alarm_reason=Pe&event_group=6&user_desc=&time=2015-08-04+15%3A38%3A19&id2=20881
*/
$replace=array(
'address'=>$arr['address'],
'company'=>$arr['extended']['company'],
'zone_id'=>$_GET['zone_id'],
'zone_desc'=>$_GET['zone_desc'],
'account_code'=>$_GET['account_code'],
'date'=>date('d M y - g:i A', strtotime($_GET['time'])),
'event_code'=>$_GET['event_code'],
'event_group'=>$_GET['event_group'],
'mac'=>$arr['extended']['mac'],
'raw_data'=>$_GET['raw_data'],
'id2'=>$_GET['id2'],
'alarm_reason'=>$_GET['alarm_reason'],
'event_desc'=>$_GET['event_desc'],
'event_alt'=>$_GET['event_alt'],
'event_state'=>$_GET['event_state'],
'user_desc'=>$_GET['user_desc'],
'name'=>$arr['fullname'],
'id'=>$arr['id'],
'idM'=>$modx->getObject('userData', array('userID')); //$arr['extended']['userID'],
'sACC'=>$modx->getObject('userData', array('sACC')); //$arr['extended']['tick']['sACC'],
'mCom'=>$modx->getObject('userData', array('MONcompany')); //$arr['extended']['MONcompany'],
'mPh'=>$modx->getObject('userData', array('MONphone')); //$arr['extended']['MONphone'],
'mEx'=>$modx->getObject('userData', array('MONexternal')); //$arr['extended']['tick']['MONexternal'],
'reportE'=>$modx->getObject('userData', array('ReportEmail')); //$arr['extended']['ReportEmail'],
);
$chunk=$modx->getChunk('mailchunk',$replace);
/* Email code here */
//sending mail
$message = $modx->getChunk('myEmailTemplate');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$chunk);
$from=(isset($from))?$from:'[email protected]';
$fname=isset($fname)?$fname:'Alarm Server';
if(isset($_GET['alarm_reason']) )
$subject='Alarm Trigger: '.$_GET['alarm_reason'];
else
$subject='Alarm Trigger';
$modx->mail->set(modMail::MAIL_FROM,$from);
$modx->mail->set(modMail::MAIL_FROM_NAME,$fname);
$modx->mail->set(modMail::MAIL_SUBJECT,$subject);
$modx->mail->address('to',$arr['email']);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
///
endif;$rem="1";
$rem2 = $modx->getObject('userData', array('ReportEmail'));
if($rem!=$rem2)
continue;