Preview: Helpers.php
Size: 8.77 KB
/home/jambtst2015/public_html/protected/components/Helpers.php
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class Helpers
{
public $a;
public $value;
public function ayan(){
$rr = "AYAN";
return $rr;
}
public static function getsingleRecord($tableName='',$value='',$getVal=''){
$criteria=new CDbCriteria();
if($tableName==1){
$criteria->compare('id',$value);
$makeModels = Exambody::model()->findAll(array("select"=>"name,id"),$criteria);
$valArray=CHtml::listData($makeModels, 'id', 'name');
return $valArray[$value];
exit;
}
if($tableName==2){
$criteria->compare('id',$value);
$makeModels = Subjectbody::model()->findAll(array("select"=>"subject,id"),$criteria);
$valArray=CHtml::listData($makeModels, 'id', 'subject');
return $valArray[$value];
exit;
}
if($tableName==3){
$criteria->compare('id',$value);
$makeModels = Questionbody::model()->findAll(array("select"=>"paper_name,id"),$criteria);
$valArray=CHtml::listData($makeModels, 'id', 'paper_name');
return $valArray[$value];
exit;
}
if($tableName==5){
$criteria->compare('id',$value);
$makeModels = Pin::model()->findAll(array("select"=>"pin_type,id"),$criteria);
$valArray=CHtml::listData($makeModels, 'id', 'pin_type');
return $valArray[$value];
exit;
}
if($tableName==7){
$criteria->select="$getVal";
$criteria->condition="field_key='$value'";
$valArray=Globalconfig::model()->find($criteria);
return $valArray->field_value;
exit;
}
if($tableName==9){
//Yii::import('application.modules.user.*');
//Yii::import('application.modules.user.models.*');
$sql = "SELECT id FROM exam_question WHERE paper_id = '".$value."'";
$data = Questionanswerbody::model()->findAllBySql($sql);
//$data = UserModule::model()->findAllBySql($sql);
//print_r($data);
return $data;
}
}
public static function getrecord($table='' , $field='',$value='',$exactField='',$exactField1='',$exactField2='',$sql=''){
$criteria=new CDbCriteria();
$criteria->select="$exactField";
if($exactField1!=''){
$criteria->select="$exactField,$exactField1";
}
if($exactField2!=''){
$criteria->select="$exactField,$exactField1,$exactField2";
}
$criteria->condition="$field='$value'";
if($sql!=''){
$criteria->condition=$criteria->condition.$sql;
}
$data = $table::model()->find($criteria);
if($exactField1!=''){
return $data;
}else{
return $data[$exactField];
}
}
public static function getallrecord($table='' , $field='',$value='',$exactField='',$exactField1='',$exactField2='',$sql=''){
$criteria=new CDbCriteria();
$criteria->select="$exactField";
if($exactField1!=''){
$criteria->select="$exactField,$exactField1";
}
if($exactField2!=''){
$criteria->select="$exactField,$exactField1,$exactField2";
}
$criteria->condition="$field='$value'";
if($sql!=''){
$criteria->condition=$criteria->condition.$sql;
}
$data = $table::model()->findAll($criteria);
if($exactField1!=''){
return $data;
}else{
return $data[$exactField];
}
}
public static function get_controler_name($position=''){
// Get HTTP/HTTPS (the possible values for this vary from server to server)
$myUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && !in_array(strtolower($_SERVER['HTTPS']),array('off','no'))) ? 'https' : 'http';
// Get domain portion
$myUrl .= '://'.$_SERVER['HTTP_HOST'];
// Get path to script
$myUrl .= $_SERVER['REQUEST_URI'];
// Add path info, if any
/*if (!empty($_SERVER['PATH_INFO'])) $myUrl .= $_SERVER['PATH_INFO'];
$get = $_GET; // Create a copy of $_GET
unset($get['lg']); // Unset whatever you don't want
if (count($get)) { // Only add a query string if there's anything left
$myUrl .= '?'.http_build_query($get);
}
$myUrl;*/
$page_name = explode('/',$myUrl);
if($position!='' && count($page_name)>$position){
$is_exit = strpos($page_name[$position],'?');
if($is_exit>0){
$exact_page_name = explode('?',$page_name[$position]);
return $exact_page_name[0];
}else{
return $page_name[$position];
}
//
}else{
return $myUrl;
}
}
public static function getMac(){
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP)){
$ip = $client;
}elseif(filter_var($forward, FILTER_VALIDATE_IP)){
$ip = $forward;
}else{
$ip = $remote;
}
//$ipAddress=$_SERVER['REMOTE_ADDR'];
$ipAddress=$ip;
//print_r($ipAddress);exit;
$macAddr=false;
#run the external command, break output into lines
$arp=`arp -a $ipAddress`;
//print_r($arp);exit;
$lines=explode("\n", $arp);
//print_r($lines);exit;
#look for the output line describing our IP address
foreach($lines as $line)
{
$cols=preg_split('/\s+/', trim($line));
if ($cols[0]==$ipAddress)
{
$macAddr=$cols[1];
}
}
return $macAddr;
}
//email template
public static function emailTempalte($pageTitle='',$heading='',$body=''){
$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$pageTitle.'</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bordercolor="#000000" style="margin:0 auto; border:#C4C4C4 1px solid;">
<tr>
<td width="600" colspan="5" style=" background:#F4F4F4; border-bottom: 1px solid #C4C4C4; height: 100px;">
<img width="205" height="59" style="padding:10px 0 10px 20px;" src="http://' . $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/images/giraffeng.com.png">
</td>
</tr>
<tr>
<td colspan="2">
<p style=" background-color: #8DC63F; color: #FFFFFF; font: bold 13px Arial,Helvetica,sans-serif; padding: 10px 0; margin:4px 0 0 0; text-align: center;">'.$heading.'</p>
</td>
</tr>
<tr>
<td colspan="2" style="padding:15px; font-family: Arial,Helvetica,sans-serif; font-size: 13px;">##EMAIL_BODY##</td>
</tr>
<tr>
<td colspan="5" style="background:#011435;">
<p style="color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 11px; padding: 6px 0;
text-align: center;">© '.date('Y').' <a href="http://' . $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/" style=" color: #ffc022; font-family: Arial,Helvetica,sans-serif; font-size: 11px; text-decoration: none;">giraffeng.com</a>. All rights reserved.</p></td>
</tr>
<td width="500"></tr>
</table>
</body>
</html>';
$email_body = str_replace(array("##EMAIL_BODY##"),array($body),$content);
return $email_body;
}
public static function getexamName($value=''){
//used for pin listing section wheather the is is mapped or not
// $valArray=CHtml::listData($makeModels, 'id', 'subject');
// return $valArray[$value];
//echo $value;
$usercriteria = new CDbCriteria();
$usercriteria->select="exam_id";
$usercriteria->condition="pin_id=$value";
$university1=Pinactivation::model()->findAll($usercriteria);
if(count($university1)>0){
$sep = '';
foreach($university1 as $university){
$makeModelshh = $university->exam_id;
if($makeModelshh!=''){
$usercriteria = new CDbCriteria();
$usercriteria->select="name";
$usercriteria->condition="id=$makeModelshh";
$university=Exambody::model()->findAll($usercriteria);
$val='';
foreach($university as $returnValue){
$val = $val.$sep.$returnValue['name'];
$sep=',';
}
echo $val;
}
}
}else{
return 'N/A';
}
}
public static function dateformat($value='',$format=''){
if($format=='mm-dd-yy' || $format=='mm/dd/yy'){
$newVal = explode('-',$value);
$formatedVal = $newVal[1].'/'.$newVal[2].'/'.$newVal[0];
}
return $formatedVal;
}
public static function getresult($userId=''){
$criteria = new CDbCriteria();
$criteria->select="*";
$criteria->addCondition("exam_user_id=".$userId);
$SubjectsArray=Examuserpaper::model()->findAll($criteria);
return $SubjectsArray;
}
public static function getresultCondition($userId='',$condition=''){
$criteria = new CDbCriteria();
$criteria->select="*";
$criteria->addCondition($condition);
$criteria->addCondition("exam_user_id=".$userId);
$SubjectsArray=Examuserpaper::model()->findAll($criteria);
return $SubjectsArray;
}
}
Directory Contents
Dirs: 0 × Files: 12