exportValues(); $data['id_email_type'] = $this->initCheckBoxListFromForm($data['id_email_type']); $data['id_email_area'] = $this->initCheckBoxListFromForm($data['id_email_area']); $data['id_email_specialty'] = $this->initCheckBoxListFromForm($data['id_email_specialty']); $this->initFromArray($data, $files); } function initFromForm(&$frm) { $files = array(); $data = $frm->exportValues(); $data[$this->pass_field] = $this->_encryptPass($data[$this->pass_field]); $data['activation_code'] = NULL; $this->arrayParseUrl2Tag($data); $this->initFromArray($data, $files); return true; } function getMemberByEmail($email) { $sql = "SELECT * FROM {$this->tableNameDB} WHERE email = ".$this->db->quote($email, 'text'); $res = $this->db->queryRow($sql); $this->_sqlError($sql); return $res; } function getMemberByActivationCode($activation_code) { $sql = "SELECT * FROM {$this->tableNameDB} WHERE activation_code = ".$this->db->quote($activation_code, 'text'); $res = $this->db->queryRow($sql); $this->_sqlError($sql); return $res; } function verifyEmail($activation_code) { $data = $this->getMemberByActivationCode($activation_code); if (!is_array($data) || empty($data)) { return 'Invalid Activation Code'; } $activation_code = md5($activation_code.time()); $this->_initTable(); $this->table->update(array('email_verified'=>'y', 'activation_code'=>$activation_code), 'id='.$this->db->quote($data['id'], 'integer')); return array('activation_code'=>$activation_code); } function verifyAccountInformation($activation_code) { $data = $this->getMemberByActivationCode($activation_code); if (!is_array($data) || empty($data)) { return 'Invalid Activation Code'; } $activation_code = md5($activation_code.time()); $this->_initTable(); $this->table->update(array('info_verified'=>'y', 'activation_code'=>$activation_code), 'id='.$this->db->quote($data['id'], 'integer')); return array('activation_code'=>$activation_code); } function sendBroadcastEmail(&$Doc, $force = false) { if ($force) { $addonSql = ''; } else { $addonSql = ' AND activation_code IS NULL '; } $sql = "SELECT COUNT(*) FROM {$this->tableNameDB} WHERE (email_verified = 'n' OR info_verified = 'n') {$addonSql}"; $cnt = $this->db->queryOne($sql); $this->_sqlError($cnt); if (!$cnt) { return array('msg'=>'All members already have activation code'); } $sql = "SELECT * FROM {$this->tableNameDB} WHERE (email_verified = 'n' OR info_verified = 'n') {$addonSql} LIMIT 10"; $res = &$this->db->query($sql); $this->_initTable(); $link = array( 'activation'=>BASE_URL.'/'.SiteMap::GetAliasByItemType('Member/Activation/Email'), 'info' =>BASE_URL.'/'.SiteMap::GetAliasByItem('HTMLBlock/Show', 'account/activation/info.html') ); ini_set('max_execution_time', 1200); require_once('class/DB/DBTable.php'); $Report = new DBTable('MemberBroadcastActivationReport'); //$this->db->query("TRUNCATE TABLE {$this->db->tblMemberBroadcastActivationReport}"); while ($row = $res->fetchRow()) { $row['link'] = $link; $row['activation_code'] = md5(rand(1,999).$row['email'].rand(1,999)); $this->table->update(array('activation_code'=>$row['activation_code']), 'id='.$this->db->quote($row['id'], 'integer')); $ret = $this->sendEmail($Doc, $row, 'New MNCAR Website: Activate your Account!'); if ($ret) { $Report->insert(array('email' => $email, 'status' => 'success', 'send_type' => 'all', 'start_time'=>$start_time)); } else { $Report->insert(array('email' => $email, 'status' => 'failed', 'send_type' => 'all', 'start_time'=>$start_time)); } } return $report; } function sendBroadcast2CustomEmails(&$Doc, $force = false, $emails) { $this->_initTable(); $link = array( 'activation'=>BASE_URL.'/'.SiteMap::GetAliasByItemType('Member/Activation/Email'), 'info' =>BASE_URL.'/'.SiteMap::GetAliasByItem('HTMLBlock/Show', 'account/activation/info.html') ); ini_set('max_execution_time', 1200); require_once('class/DB/DBTable.php'); $Report = new DBTable('MemberBroadcastActivationReport'); //$this->db->query("TRUNCATE TABLE {$this->db->tblMemberBroadcastActivationReport}"); $start_time = date('Y-m-d H:i:s'); foreach ($emails as $email) { $row = $this->getMemberByEmail($email); if (!(int)$row['id']) { $Report->insert(array('email' => $email, 'status' => 'not_found', 'send_type' => 'custom', 'start_time' => $start_time)); continue; } if ($row['email_verified'] == 'y' && $row['info_verified'] == 'y') { $Report->insert(array('email' => $email, 'status' => 'already_activated', 'send_type' => 'custom', 'start_time' => $start_time)); continue; } if (!$force && !empty($row['activation_code'])) { $Report->insert(array('email' => $email, 'status' => 'already_recieved', 'send_type' => 'custom', 'start_time' => $start_time)); continue; } $row['link'] = $link; $row['activation_code'] = $this->getUniqueActivationCode(); $this->table->update(array('activation_code'=>$row['activation_code']), 'id='.$this->db->quote($row['id'], 'integer')); $ret = $this->sendEmail($Doc, $row, 'New MNCAR Website: Activate your Account!'); if ($ret) { $Report->insert(array('email' => $email, 'status' => 'success', 'send_type' => 'custom', 'start_time'=>$start_time)); } else { $Report->insert(array('email' => $email, 'status' => 'failed', 'send_type' => 'custom', 'start_time'=>$start_time)); } } } function getBroadcastActivationReport() { $max_start_time = $this->db->queryOne("SELECT MAX(start_time) FROM {$this->db->tblMemberBroadcastActivationReport} ORDER BY status"); if (!$max_start_time) return false; $sql = " SELECT * FROM {$this->db->tblMemberBroadcastActivationReport} WHERE start_time = ".$this->db->quote($max_start_time)." "; $list = $this->db->queryAll($sql); return $list; } function getUniqueActivationCode() { do { list($usec, $sec) = explode(" ",microtime()); $code = md5(time().rand(1, 300).(((float)$usec + (float)$sec))); } while (!$this->isUniqueActivationCode($code)); return $code; } function isUniqueActivationCode($code) { $sql = "SELECT COUNT(*) FROM {$this->db->tblMember} WHERE activation_code = ".$this->db->quote($code, 'text'); return !(bool)$this->db->queryOne($sql); } function sendEmail(&$Doc, $data, $subject = null) { require_once('class/Const.php'); Constant::set('DEBUG', false); $Doc->assign('item', $data); $Doc->setMainTpl('Member/Activation/email.tpl'); $html = $Doc->fetch(); require_once ('lib/htmlMimeMail/htmlMimeMail.php'); $mail = new htmlMimeMail(); $mail->setHtml($html); require_once('app/Settings/Settings.php'); $mail->setFrom(Settings::get('admin_email_from')); if (empty($subject)) { $subject = 'Account Activation at mncar.org'; } $mail->setSubject($subject); $mail->setHeader('X-Mailer', 'HTML Mime mail class'); return $mail->send(array($data['email'])); } function updateProfile($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); //$this->table->update($this->_data, 'id = '. $this->db->quote($this->id, 'integer') ); $this->updateIds($this->tableNameDB.'2EmailType', 'id_email_type', $this->_data['id_email_type']); $this->updateEmailAreaIds($this->_data['id_email_area']); $this->updateIds($this->tableNameDB.'2EmailSpecialty', 'id_specialty', $this->_data['id_email_specialty']); } }