my client ask me to show the in and out of their employees from biometrics..i already did it but it only shows data for 1 day. Can somebody help me..If you can see I had a lot of codes there and it doesn't satisfy my client.I'am working on it for almost a month
this is my code..I'm a beginner.
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_REQUEST['startdate']) && isset($_REQUEST['enddate']))
{
$startdate = $_REQUEST['startdate'];
$enddate = $_REQUEST['enddate'];
$shiftdate = $_REQUEST['shiftdate'];
$category= $_REQUEST['category'];
$counterless = 0;
$ncounter = 0;
$count =0 ;
$loop=0;
$holder=0;
$checker=0;
$wala = 0;
$present = 0;
/*$_SESSION['nightname'] = array();
$_SESSION['nighttime'] = array();
$_SESSION['testname'] = array();
$_SESSION['testtime'] = array();*/
$con = mysqli_connect("localhost","root","","testingdb");
$connect = mysqli_connect("localhost","root","","inoutchecking");
mysqli_query($con,"delete from forprint");
mysqli_query($con,"delete from absentforprint");
$result = mysqli_query($con,"select * from wawart where Column_2 = '$startdate' order by Column_2 asc");
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
$time = $row['Column_3'];
$times = (int)($time);
$inout = $row['Column_4'];
$dates = $row['Column_2'];
if(($times <= 14 and $inout == '1') or ($times >=17 and $inout == '4'))
{
$_SESSION['testname'][$counterless] = $row['Column_1'];
$_SESSION['testtime'][$counterless] = $time;
$counterless++;
}
if(($times <= 20 and $times >= 15) and $inout == '1')
{
$_SESSION['nightname'][$ncounter] = $row['Column_1'];
$_SESSION['nighttime'][$ncounter] = $time;
$ncounter++;
}
}
$wala=1;
}
else
{
$wala=0;
}
if($category == 'dayshift')
{
$shift = 'Day Shift';
}
else if($category == 'nightshift')
{
$shift = 'Night Shift';
}
else
{
$shift = 'Night Shift and Day Shift';
}
echo "<label class='cat'>".$shift."</label>";
echo "<label class='absent'>Absentees ".$startdate."</label>";
if($category == 'dayshift')
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('Employee Number','Lastname','Firstname','Department','Section','Time in','Time out','Shift')");
echo "<div class='dayshift'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th><th>DATE</th><th>IN</th><th>OUT</th></tr>";
for($x = 0; $x<$counterless;$x++)
{
$dempid = $_SESSION['testname'][$x];
$day = mysqli_query($connect,"select * from nightshiftlist where empid = '$dempid' and shift ='dayshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$count++;
if($loop == '1')
{
echo "<td>NO OUT</td></tr>";
$loop=0;
}
$empid = $empinfo['empid'];
$empshift = $empinfo['shift'];
$name = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
$checking = mysqli_query($con,"select * from wawart where Column_1='$empid' and (Column_2 between '$startdate' and '$enddate') order by Column_2 asc");
if($holder == $empinfo['empid'])
{
break;
}
echo"<tr><td>".$empinfo['empid']."</td><td>".$empinfo['lastname']."</td><td>".$empinfo['firstname']."</td><td>".$empinfo['department']."</td><td>".$empinfo['section']."</td>";
if(mysqli_num_rows($checking)>0)
{
while($row=mysqli_fetch_array($checking))
{
$time = $row['Column_3'];
$times = (int)$time;
if($holder == $empinfo['empid'])
{
break;
}
else
{
$inout = $row['Column_4'];
$time = $row['Column_3'];
if($loop ==0)
{
$date = $row['Column_2'];
echo"<td>".$row['Column_2']."</td>";
}
if($loop ==0 )
{
if($inout == '1')
{
$timein = $time;
echo "<td>".$time."</td>";
$loop = 1;
}
if($inout == '4')
{
$timein = 'NO IN';
$timeout = $time;
echo "<td><B>NO IN</td><td>".$time."</td></tr>";
$holder = $empinfo['empid'];
$loop = 0;
}
}
else
{
if($loop =='1' && $inout == '4')
{
$timeout = $time;
echo "<td>".$time."</td></tr>";
}
if($loop =='1' && $inout == '1')
{
$timeout = 'NO OUT';
echo "<td><B>NO OUT</td></tr>";
}
$loop = 0;
$counter = 0;
$holder = $empinfo['empid'];
$checker = 2;
if($checker == 2)
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('$empid','$name','$fname','$dept','$section','$timein','$timeout','$empshift')");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
}
}
}
}
ini_set('max_execution_time', 999999);
}
}
echo"</table></div>";
/*absentees*/
if($wala == 1)
{
$count = 0;
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('Employee Number','Lastname','Firstname','Department','Section')");
echo "<div class='absentees'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th></tr>";
$day = mysqli_query($connect,"select * from nightshiftlist where shift ='dayshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$id = $empinfo['empid'];
$shift = $empinfo['shift'];
$lname = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$date = $empinfo['datefrom'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
for($x = 0; $x<$counterless;$x++)
{
$dempid = $_SESSION['testname'][$x];
if($id == $dempid)
{
$present = 1;
break;
}
else
{
$present = 0;
}
ini_set('max_execution_time', 999999);
}
if($present == 0)
{
echo "<tr><td>".$id."</td><td>".$lname."</td><td>".$fname."</td><td>".$dept."</td><td>".$section."</td></tr>";
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('$id','$lname','$fname','$dept','$section')");
ini_set('max_execution_time', 999999);
$count++;
}
}
echo"</table></div>";
echo"<label class='totalabs'>Total Number of Absentees ".$count."</label>";
}
}/*end of absentees*/
if($category == 'nightshift')
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('Employee Number','Lastname','Firstname','Department','Section','Time in','Time out','Shift')");
echo "<div class='dayshift'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DATE</th><th>DEPARTMENT</th><th>SECTION</th><th>IN</th><th>OUT</th></tr>";
for($x = 0; $x<$ncounter;$x++)
{
$dempid = $_SESSION['nightname'][$x];
$day = mysqli_query($connect,"select * from nightshiftlist where empid = '$dempid' and shift = 'nightshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$count++;
if($loop == '1')
{
echo "<td>NO OUT</td></tr>";
$loop=0;
}
$empid = $empinfo['empid'];
$empshift = $empinfo['shift'];
$name = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
$checking = mysqli_query($con,"select * from wawart where Column_1='$empid' and (Column_2 between '$startdate' and '$enddate') order by Column_2 asc");
if($holder == $empinfo['empid'])
{
break;
}
echo"<tr><td>".$empinfo['empid']."</td><td>".$empinfo['lastname']."</td><td>".$empinfo['firstname']."</td><td>".$empinfo['department']."</td><td>".$empinfo['section']."</td>";
if(mysqli_num_rows($checking)>0)
{
while($row=mysqli_fetch_array($checking))
{
$time = $row['Column_3'];
$times = (int)$time;
if($holder == $empinfo['empid'])
{
break;
}
else
{
$inout = $row['Column_4'];
$time = $row['Column_3'];
$dates = $row['Column_2'];
if($loop ==0 && $inout == '1'&& $dates == $startdate)
{
$date = $row['Column_2'];
echo"<td>".$row['Column_2']."</td>";
}
if($loop ==0 && $dates == $startdate)
{
if($inout == '1')
{
$timein = $time;
echo "<td>".$time."</td>";
$loop = 1;
}
if($inout == '4')
{
$timein = 'NO IN';
$loop = 0;
}
}
else
{
if($loop =='1' && $inout == '4')
{
$timeout = $time;
echo "<td>".$time."</td></tr>";
}
if($loop =='1' && $inout == '1')
{
$timeout = 'NO OUT';
echo "<td><B>NO OUT</td></tr>";
}
$loop = 0;
$counter = 0;
$holder = $empinfo['empid'];
$checker = 2;
if($checker == 2)
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('$dempid','$name','$fname','$dept','$section','$timein','$timeout','$empshift')");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
}
}
}
}
ini_set('max_execution_time', 999999);
}
}
echo"</table></div>";
/*absentees*/
if($wala == 1)
{
$count = 0;
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('Employee Number','Lastname','Firstname','Department','Section')");
echo "<div class='absentees'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th></tr>";
$day = mysqli_query($connect,"select * from nightshiftlist where shift ='nightshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$id = $empinfo['empid'];
$shift = $empinfo['shift'];
$lname = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
for($x = 0; $x<$ncounter;$x++)
{
$dempid = $_SESSION['nightname'][$x];
if($id == $dempid)
{
$present = 1;
break;
}
else
{
$present = 0;
}
ini_set('max_execution_time', 999999);
}
if($present == 0)
{
echo "<tr><td>".$id."</td><td>".$lname."</td><td>".$fname."</td><td>".$dept."</td><td>".$section."</td></tr>";
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('$id','$lname','$fname','$dept','$section')");
$count++;
}
ini_set('max_execution_time', 999999);
}
echo"</table></div>";
echo"<label class='totalabs'>Total Number of Absentees ".$count."</label>";
}
}/*end of absentees*/
}
?>
The first sql select query you are executing needs to be corrected.Your select sql query does not considering end date. Try the below query
$result = mysqli_query($con,"select * from wawart where Column_2 >= '$startdate' and Column_2 <= '$enddate' order by Column_2 asc");
Related
My problem occurs when I call this file readXML.php from the cron job in cPanel (that's not working).
I tried some commands:
/usr/local/bin/php -q /home/myUserName/public_html/readXML.php
/usr/local/bin/php /home/myUserName/public_html/readXML.php
php -q /home/myUserName/public_html/readXML.php
php /home/myUserName/public_html/readXML.php
But the commands are not working (they don't do anything).
My script is working 100% when I call them from the URL:
(www.mysite.com/readXML.php)
But I want to run this file automatically every 10 minutes.
*/10 * * * * And what's the command?
Cron Job in cPanel
<?php
include 'init.php';
global $dataFetchAll, $sahaID, $sourID, $deptID, $cateID, $deptNAME, $cateNAME,
$newsTITLE, $newsDESC, $newsLINK, $newsDATE, $newsIMAGE;
$allFeedLinks = GetAllFeedLinks();
try
{
foreach ($allFeedLinks as $link)
{
$url = $link['SourFEEDLINK'];
$sourID = 0;
$sahaID = 0;
$deptID = 0;
$cateID = 0;
$deptNAME = "";
$cateNAME = "";
getInfoSource("SourFEEDLINK", $url);
$sourID = $sourceID;
if($sourceDeptID > 0)
{
$deptID = $sourceDeptID;
getInfoDept("DeptID", $deptID);
}
if($sourceSahaID > 0)
{
$sahaID = $sourceSahaID;
}
if(($methodXML == 0) || ($methodXML == 1))
{
if($methodXML == 0)
{
$lines_string=file_get_contents($url);
$xml = new SimpleXMLElement($lines_string);
}
else if($methodXML == 1)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36');
$feed = curl_exec($ch);
$xml = new SimpleXMLElement($feed);
}
for ($i = 0; $i < 5; $i++)
{
$newsTITLE = "";
$newsLINK = "";
$newsDESC = "";
$newsDATE = "";
$newsIMAGE = "";
if((isset($xml->channel->item[$i]->title)) && (!empty($xml->channel->item[$i]->title)))
{
$newsTITLE = $xml->channel->item[$i]->title;
$rowNews = CheckNews("NewsTITLE", $newsTITLE);
if($rowNews <= 0)
{
if((isset($xml->channel->item[$i]->link)) && (!empty($xml->channel->item[$i]->link)))
$newsLINK = $xml->channel->item[$i]->link;
if((isset($xml->channel->item[$i]->description)) && (!empty($xml->channel->item[$i]->description)))
{
$newsDESC = $xml->channel->item[$i]->description;
$newsDESC = RemoveTags($newsDESC);
}
if((isset($xml->channel->item[$i]->pubDate)) && (!empty($xml->channel->item[$i]->pubDate)))
{
$pDate = $xml->channel->item[$i]->pubDate;
$stringDate = ModifyDateString($pDate);
date_default_timezone_set('Asia/Riyadh');
$xDate = date("Y-m-d H:i:s", strtotime($stringDate));
$dateInNum = strtotime($xDate);
$current_time = time();
$result = $current_time - $dateInNum;
if($result >= 0)
$newsDATE = $xDate;
else
{
date_default_timezone_set('Asia/Riyadh');
$date = explode(" ", $stringDate);
$day = $date[0];
$d = $date[1];
$month = $date[2];
$year = $date[3];
$theTime = $date[4];
$newsDATE = $day ." " .$d ." " .$month ." " .$year ." " .$theTime;
$newsDATE = date("Y-m-d H:i:s", strtotime($newsDATE));
}
}
if((isset($xml->channel->item[$i]->enclosure['url'])) && (!empty($xml->channel->item[$i]->enclosure['url'])))
$newsIMAGE = $xml->channel->item[$i]->enclosure['url'];
if($deptID == 0)
{
if((isset($xml->channel->item[$i]->category)) && (!empty($xml->channel->item[$i]->category)))
$cateNAME = $xml->channel->item[$i]->category;
if((empty($cateNAME)) || ($cateNAME==""))
$cateNAME = "الاخبار";
$rowCate = VerifyCategory("CateNAME", $cateNAME);
if($rowCate <= 0)
{
InsertCatedgoryToDB();
getInfoCategory("CateNAME", $cateNAME);
}
}
if((!empty($newsTITLE)) && (!empty($newsLINK)) && (!empty($newsDATE)))
{
InsertNewsToDB();
}
}
}
}
}
else
{
$xmlDoc = new DOMDocument();
$xmlDoc->load($url);
$x = $xmlDoc->getElementsByTagName('item');
for ($i = 0; $i < 5; $i++)
{
$newsTITLE = "";
$newsLINK = "";
$newsDESC = "";
$newsDATE = "";
$newsIMAGE = "";
if(!empty($x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue))
{
$newsTITLE =$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$rowNews = CheckNews("NewsTITLE", $newsTITLE);
if($rowNews <= 0)
{
if(!empty($x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue))
$newsLINK = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
if(!empty($x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue))
$newsLINK = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
else if((empty($newsLINK)) && (!empty($x->item($i)->getElementsByTagName('link')->item(0)->attributes['href']->nodeValue)))
$newsLINK = $x->item($i)->getElementsByTagName('link')->item(0)->attributes['href']->nodeValue;
if(!empty($x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue))
{
$newsDESC = $x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
$newsDESC = RemoveTags($newsDESC);
}
if((!empty($x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue)))
{
$pDate = $x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue;
$stringDate = ModifyDateString($pDate);
date_default_timezone_set('Asia/Riyadh');
$xDate = date("Y-m-d H:i:s", strtotime($stringDate));
$dateInNum = strtotime($xDate);
$current_time = time();
$result = $current_time - $dateInNum;
if($result >= 0)
$newsDATE = $xDate;
else
{
date_default_timezone_set('Asia/Riyadh');
$date = explode(" ", $stringDate);
$day = $date[0];
$d = $date[1];
$month = $date[2];
$year = $date[3];
$theTime = $date[4];
$newsDATE = $day ." " .$d ." " .$month ." " .$year ." " .$theTime;
$newsDATE = date("Y-m-d H:i:s", strtotime($newsDATE));
}
}
if(!empty($x->item($i)->getElementsByTagName('enclosure')->item(0)->attributes['url']->nodeValue))
$newsIMAGE = $x->item($i)->getElementsByTagName('enclosure')->item(0)->attributes['url']->nodeValue;
if($deptID == 0)
{
if((!empty($x->item($i)->getElementsByTagName('category')->item(0)->childNodes->item(0)->nodeValue)))
$cateNAME = $x->item($i)->getElementsByTagName('category')->item(0)->childNodes->item(0)->nodeValue;
if((empty($cateNAME)) || ($cateNAME==""))
$cateNAME = "الاخبار";
$rowCate = VerifyCategory("CateNAME", $cateNAME);
if($rowCate <= 0)
{
InsertCatedgoryToDB();
getInfoCategory("CateNAME", $cateNAME);
}
}
if((!empty($newsTITLE)) && (!empty($newsLINK)) && (!empty($newsDATE)))
{
InsertNewsToDB();
}
}
}
}
}
}
}
catch(PDOException $e){
echo $e->getMessage();
}
?>
I'm trying to figure out how to make this code work.
I input some text via variable into code:
$genome = "ss/ee/ff/Nn/oo";
$gepieces = explode("/", $genome);
$fenome = "ss/Ee/ff/nn/oo";
$fepieces = explode("/", $fenome);
You will see that for the Genome there is a Nn and for the Fenome there is a Ee
Upon this happening I need it to give a 50/50 chance for a compared result to be EITHER Ee OR Nn - The code I have right now can only check them individually (so sometimes I ger Ee AND Nn, other times I will get ee and nn) and I feel there could be a much easier method of achieving this than what I'm trying:
//Number of Cubs
$cubs = rand(1,4);
//GENDER
for ($x = 0; $x < $cubs; $x++) {
$gender = rand(1,2);
if ($gender == 1) {
$cubgender = "Male";
} elseif ($gender == 2) {
$cubgender = "Female";
}
//COAT COLOR
$genome = "ss/ee/ff/Nn/oo/Pa/Sr/So";
$gepieces = explode("/", $genome);
$fenome = "ss/Ee/ff/nn/oo/Pa";
$fepieces = explode("/", $fenome);
if ($gepieces[0] === $fepieces[0]) {
$ss = $gepieces[0];
} else {
$ss = rand(1,2);
if ($ss == 1) {
$ss = $gepieces[0];
} else {
$ss = $fepieces[0];
}
}
if ($gepieces[1] === $fepieces[1]) {
$ee = $gepieces[1];
} else {
$ee = rand(1,2);
if ($ee == 1) {
$ee = $gepieces[1];
} else {
$ee = $fepieces[1];
}
}
if ($gepieces[2] === $fepieces[2]) {
$ff = $gepieces[2];
} else {
$ff = rand(1,2);
if ($ff == 1) {
$ff = $gepieces[2];
} else {
$ff = $fepieces[2];
}
}
if ($gepieces[3] === $fepieces[3]) {
$nn = $gepieces[3];
} else {
$nn = rand(1,2);
if ($nn == 1) {
$nn = $gepieces[3];
} else {
$nn = $fepieces[3];
}
}
if ($gepieces[4] === $fepieces[4]) {
$oo = $gepieces[4];
} else {
$oo = rand(1,2);
if ($oo == 1) {
$oo = $gepieces[4];
} else {
$oo = $fepieces[4];
}
}
echo $cubgender." - ".$ss."/".$ee."/".$ff."/".$nn."/".$oo."<br/>";
}
I'm a colossal idiot!
Figured out my own issue
//Number of Cubs
$cubs = rand(1,4);
//GENDER
for ($x = 0; $x < $cubs; $x++) {
$gender = rand(1,2);
if ($gender == 1) {
$cubgender = "Male";
} elseif ($gender == 2) {
$cubgender = "Female";
}
//COAT COLOR
$genome = "ss/ee/ff/Nn/oo";
$gepieces = explode("/", $genome);
$fenome = "ss/Ee/ff/nn/oo";
$fepieces = explode("/", $fenome);
if ($genome === $fenome) {
$cubgeno = $genome;
} else {
$cubgeno = rand(1,2);
if ($cubgeno == 1) {
$cubgeno = $genome;
} else {
$cubgeno = $fenome;
}
}
echo $cubgender." - ".$cubgeno."<br/>";
$genome = "ss/ee/ff/Nn/oo/Pa/Sr/So";
$gepieces = explode("/", $genome);
$fenome = "ss/Ee/ff/nn/oo/Pa";
$fepieces = explode("/", $fenome);
$sequence = "";
for ($i = 0;$i < count($fepieces); $i++) {
rand(1,2) == 1 ? $sequence .= $gepieces[$i] : $sequence .= $fepieces[$i];
}
echo $sequence;
i have a module which executes two functions. the first filters and showsthe latest comments per category. the second one filters and shows the top commenters of all categories. i want to hack it in order to show the top commenters per category. for the first one there is in the backend the option to select category but for the top commenters there is not.
here is the code of the module. forgive me for its length.
class modK2CommentsHelper
{
public static function getLatestComments(&$params)
{
$mainframe = JFactory::getApplication();
$limit = $params->get('comments_limit', '5');
$user = JFactory::getUser();
$aid = $user->get('aid');
$db = JFactory::getDBO();
$cid = $params->get('category_id', NULL);
$jnow = JFactory::getDate();
$now = K2_JVERSION != '15' ? $jnow->toSql() : $jnow->toMySQL();
$nullDate = $db->getNullDate();
$model = K2Model::getInstance('Item', 'K2Model');
$componentParams = JComponentHelper::getParams('com_k2');
$query = "SELECT c.*, i.catid, i.title, i.alias, category.alias as catalias, category.name as categoryname
FROM #__k2_comments as c
LEFT JOIN #__k2_items as i ON i.id=c.itemID
LEFT JOIN #__k2_categories as category ON category.id=i.catid
WHERE i.published=1
AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." )
AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )
AND i.trash=0 ";
if (K2_JVERSION != '15')
{
$query .= " AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
}
else
{
$query .= " AND i.access<={$aid} ";
}
$query .= " AND category.published=1 AND category.trash=0 ";
if (K2_JVERSION != '15')
{
$query .= " AND category.access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
}
else
{
$query .= " AND category.access<={$aid} ";
}
$query .= " AND c.published=1 ";
if ($params->get('catfilter'))
{
if (!is_null($cid))
{
if (is_array($cid))
{
JArrayHelper::toInteger($cid);
$query .= " AND i.catid IN(".implode(',', $cid).")";
}
else
{
$query .= " AND i.catid=".(int)$cid;
}
}
}
if (K2_JVERSION != '15')
{
if ($mainframe->getLanguageFilter())
{
$languageTag = JFactory::getLanguage()->getTag();
$query .= " AND category.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") AND i.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').")";
}
}
$query .= " ORDER BY c.commentDate DESC ";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$pattern = "#\b(https?://)?(([0-9a-zA-Z_!~*'().&=+$%-]+:)?[0-9a-zA-Z_!~*'().&=+$%-]+\#)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\#&=+$,%#-]+)*/?)#";
if (count($rows))
{
foreach ($rows as $row)
{
if ($params->get('commentDateFormat') == 'relative')
{
$config = JFactory::getConfig();
$now = new JDate();
if (K2_JVERSION == '30')
{
$tzoffset = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
$now->setTimezone($tzoffset);
}
else
{
$tzoffset = $config->getValue('config.offset');
$now->setOffset($tzoffset);
}
$created = new JDate($row->commentDate);
$diff = $now->toUnix() - $created->toUnix();
$dayDiff = floor($diff / 86400);
if ($dayDiff == 0)
{
if ($diff < 5)
{
$row->commentDate = JText::_('K2_JUST_NOW');
}
elseif ($diff < 60)
{
$row->commentDate = $diff.' '.JText::_('K2_SECONDS_AGO');
}
elseif ($diff < 120)
{
$row->commentDate = JText::_('K2_1_MINUTE_AGO');
}
elseif ($diff < 3600)
{
$row->commentDate = floor($diff / 60).' '.JText::_('K2_MINUTES_AGO');
}
elseif ($diff < 7200)
{
$row->commentDate = JText::_('K2_1_HOUR_AGO');
}
elseif ($diff < 86400)
{
$row->commentDate = floor($diff / 3600).' '.JText::_('K2_HOURS_AGO');
}
}
}
$row->commentText = K2HelperUtilities::wordLimit($row->commentText, $params->get('comments_word_limit'));
$row->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\0">\0</a>', $row->commentText);
$row->itemLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->itemID.':'.urlencode($row->alias), $row->catid.':'.urlencode($row->catalias))));
$row->link = $row->itemLink."#comment{$row->id}";
$row->catLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->catid.':'.urlencode($row->catalias))));
if ($row->userID > 0)
{
$row->userLink = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
$getExistingUser = JFactory::getUser($row->userID);
$row->userUsername = $getExistingUser->username;
}
else
{
$row->userUsername = $row->userName;
}
// Switch between commenter name and username
if ($params->get('commenterName', 1) == 2)
$row->userName = $row->userUsername;
$row->userImage = '';
if ($params->get('commentAvatar'))
{
$row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
}
$comments[] = $row;
}
return $comments;
}
}
public static function getTopCommenters(&$params)
{
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'tables');
$limit = $params->get('commenters_limit', '5');
$user = JFactory::getUser();
$aid = $user->get('aid');
$db = JFactory::getDBO();
$query = "SELECT COUNT(id) as counter, userName, userID, commentEmail FROM #__k2_comments WHERE userID > 0 AND published = 1 GROUP BY userID ORDER BY counter DESC";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$pattern = "#\b(https?://)?(([0-9a-zA-Z_!~*'().&=+$%-]+:)?[0-9a-zA-Z_!~*'().&=+$%-]+\#)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\#&=+$,%#-]+)*/?)#";
$model = K2Model::getInstance('Item', 'K2Model');
$componentParams = JComponentHelper::getParams('com_k2');
if (count($rows))
{
foreach ($rows as $row)
{
if ($row->counter > 0)
{
$row->link = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
if ($params->get('commenterNameOrUsername', 1) == 2)
{
$getExistingUser = JFactory::getUser($row->userID);
$row->userName = $getExistingUser->username;
}
if ($params->get('commentAvatar'))
{
$row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
}
if ($params->get('commenterLatestComment'))
{
$query = "SELECT * FROM #__k2_comments WHERE userID = ".(int)$row->userID." AND published = 1 ORDER BY commentDate DESC";
$db->setQuery($query, 0, 1);
$comment = $db->loadObject();
$item = JTable::getInstance('K2Item', 'Table');
$item->load($comment->itemID);
$category = JTable::getInstance('K2Category', 'Table');
$category->load($item->catid);
$row->latestCommentText = $comment->commentText;
$row->latestCommentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\0">\0</a>', $row->latestCommentText);
$row->latestCommentLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias), $item->catid.':'.urlencode($category->alias))))."#comment{$comment->id}";
$row->latestCommentDate = $comment->commentDate;
}
$commenters[] = $row;
}
}
if (isset($commenters))
return $commenters;
}
}
}
every help is appreciated. thank you very much
I'm struggling with the following problem since 9 hours and can't find the solution. I'm using a very old script from here (http://www.teralaser.net/invitephp/) to build an invitation-script. I already did all the styling within the past week and it looks great, now.
the script stores the single datasets in a .dat file. Now I realized, that it always keeps just the first 125 lines of the database and deletes the rest. That's a hug he problem, as it is for an invitation with nearly 1000 persons.
After some hours I found out (better I guess), that it's the following line, which destroys it:
case "adminadd":
if (isset($_POST["pwd"])) $pwd = $_POST["pwd"];
else $pwd="";
$pwdchk = 1;
if (isset($_GET["pwd2"])) $pwdchk = strcasecmp(md5( date("z") . $admin_password),$_GET["pwd2"]);
if (strcasecmp($pwd,$admin_password) != 0 && $pwdchk != 0) {
echo "<HTML><HEAD><META HTTP-EQUIV='REFRESH' CONTENT='1; URL=$PHP_SELF?do=admin'></HEAD><BODY bgcolor='#ffffff'><CENTER><H2>Falsches Passwort!</H2>Bitte warten...</CENTER></BODY><HTML>";
exit;
}
// Get all administrator changes
$record = file($data_file);
rsort($record);
$jmlrec = count($record);
// Delete duplicates (the dum way...) and get host email if any
$hostemail = "";
for ($i = 0; $i < $jmlrec; $i++) {
if (isset($record[$i])) {
$r = $record[$i];
$row = explode("|~~|",$r);
$chkmail = $row[2];
if ($row[4] == "Gastgeber") $hostemail = $row[2];
for($j = $i+1; $j < $jmlrec; $j++) {
$r = $record[$j];
$row = explode("|~~|",$r);
if (strcasecmp($row[2],$chkmail)==0 ) { $record[$j] = ""; }
}
}
}
$updno = 0;
$err = 0;
for ($i = 0; $i < $jmlrec; $i++) { // Geändert von $jmlrec+12
// Changes ?
if (isset($_POST["vemail".$i])) $chkmail = $_POST["vemail".$i]; else $chkmail ="";
$found = -1;
if ($chkmail != "") {
// Find existing record if possible...
$recno = count($record);
for($j = 0; $j < $recno; $j++) {
$r = $record[$j];
$row = explode("|~~|",$r);
if (strcasecmp($row[2],$chkmail) == 0) { $found = $j; break; }
}
$changed = 1;
if ($found >= 0) {
// Changed ?
if ( $row[2] == $_POST["vemail".$i] && $row[3] == $_POST["vname".$i] && $row[4] == $_POST["vreply".$i] && $row[5] == $_POST["vamount".$i] &&
$row[6] == $_POST["vcompany".$i] && $row[7] == $_POST["vcomment".$i] ) $changed = 0;
}
if ( $changed != 0 ) {
$updno++;
$idx = date("YmdHis");
$tgl = date("d.m.Y H:i");
$vemail = str_replace("<","",$_POST["vemail".$i]);
$vemail = str_replace(">","",$vemail);
$vemail = str_replace("~~","--",$vemail);
$vemail = str_replace("\"",""",$vemail);
$vname = str_replace("<","",$_POST["vname".$i]);
$vname = str_replace(">","",$vname);
$vname = str_replace("~","-",$vname);
$vname = str_replace("\"",""",$vname);
$vreply = str_replace("<","",$_POST["vreply".$i]);
$vreply = str_replace(">","",$vreply);
if ($vreply != "ungesehen" && $vreply != "gesehen" && $vreply != "unentschlossen" && $vreply != "abgesagt" && $vreply != "zugesagt" && $vreply != "Gastgeber") $vreply = "ungesehen";
if ($vreply != "Gastgeber" && $vreply != "ungesehen" && $found >= 0 ) $tgl = $tgl . "*"; // admin change
$vamount = str_replace("<","<",$_POST["vamount".$i]);
$vamount = str_replace(">",">",$vamount);
$vamount = str_replace("~","-",$vamount);
$vamount = str_replace("\"",""",$vamount);
$vcomment = str_replace("<","<",$_POST["vcomment".$i]);
$vcomment = str_replace(">",">",$vcomment);
$vcomment = str_replace("~","-",$vcomment);
$vcomment = str_replace("\"",""",$vcomment);
$vcompany = str_replace("<","<",$_POST["vcompany".$i]);
$vcompany = str_replace(">",">",$vcompany);
$vcompany = str_replace("~","-",$vcompany);
$vcompany = str_replace("\"",""",$vcompany);
if (strtoupper($os) == "WIN") {
$vcomment = str_replace("\r\n","<BR>",$_POST["vcomment".$i]);
$vcomment = str_replace("\r","",$vcomment);
$vcomment = str_replace("\n","",$vcomment);
} else {
$vcomment = str_replace("\n","<BR>",$vcomment);
$vcomment = str_replace("\r","",$vcomment);
}
$validemail = 1;
if (!preg_match("/([\w\.\-]+)(\#[\w\.\-]+)(\.[a-z]{2,4})+/i", $vemail)) $validemail = 0;
if ( $vname != "" && $validemail == 0 ) { echo "Email not valid for $vname : $vemail <br>"; $err++; }
if ( $vname != "" && $validemail == 1 ) {
if ($found < 0 ) { $record[] = "\n"; $found = count($record) - 1; }
$newdata = "<?//|~~|$idx|~~|$vemail|~~|$vname|~~|$vreply|~~|$vamount|~~|$vcompany|~~|$vcomment|~~|$tgl|~~|?>\n";
$newdata = "!" . stripslashes($newdata);
$record[$found] = $newdata;
} else {
if ( $vname != "") { $updno--; $changed = 0; }
}
}
if ( $changed == 0 ) {
if ($found >= 0) $record[$found] = "!".$record[$found];
}
}
}
// Quick add
$quickadd = "";
if (isset($_POST["quickadd"]) && $_POST["quickadd"] != "") $quickadd = stripslashes($_POST["quickadd"]);
if (trim($quickadd) != "") {
$qadd = explode("\"",$quickadd);
$qaddn = count($qadd);
$nametoadd = "";
$companytoadd = "";
for($i = 0; $i < $qaddn; $i++) {
if ($i % 2 == 0) {
$q2 = explode(",",$qadd[$i]);
$q2n = count($q2);
for($j = 0; $j < $q2n; $j++) {
$mailtoadd = trim($q2[$j]);
$mailtoadd = str_replace("<","",$mailtoadd);
$mailtoadd = str_replace(">","",$mailtoadd);
$mailtoadd = str_replace("~~","--",$mailtoadd);
if ($mailtoadd != "") {
$validemail = 1;
if (!preg_match("/([\w\.\-]+)(\#[\w\.\-]+)(\.[a-z]{2,4})+/i", $mailtoadd)) $validemail = 0;
if ($validemail == 0 ) { echo "Fehler bei $mailtoadd (Keine gültige eMail-Addresse)"; $err++; } else {
if ($nametoadd == "") { $nametoaddarr = explode("#",$mailtoadd); $nametoadd = $nametoaddarr[0]; }
$idx = date("YmdHis");
$newdata = "<?//|~~|$idx|~~|$mailtoadd|~~|$nametoadd|~~|ungesehen|~~|1|~~|$companytoadd|~~||~~|?>\n";
$newdata = "!" . stripslashes($newdata);
$record[]= $newdata;
$nametoadd = "";
$companytoadd = "";
}
}
}
}
if ($i % 2 == 1) {
$data = $qadd[$i];
list($nametoadd, $companytoadd) = explode(";", $data);
$nametoadd = str_replace("<","" ,$nametoadd);
$nametoadd = str_replace(">","" ,$nametoadd);
$nametoadd = str_replace("~","-",$nametoadd);
$companytoadd = str_replace("|","" ,$companytoadd);
$companytoadd = str_replace("<","" ,$companytoadd);
$companytoadd = str_replace(">","" ,$companytoadd);
$companytoadd = str_replace("~","-",$companytoadd);
}
}
}
/* Hier liegt der tote Fuchs begraben!!! */
$jmlrec = count($record);
$update_data = fopen($data_file,"w");
if (strtoupper($os) == "UNIX") {
if (flock($update_data,LOCK_EX)) {
for ($j=0; $j<$jmlrec; $j++) {
if (strncasecmp($record[$j],"!",1) != 0 ) $updno++;
if ($record[$j] != "" && strncasecmp($record[$j],"!",1) == 0 ) fputs($update_data,substr($record[$j],1));
}
flock($update_data,LOCK_UN);
}
} else {
for ($j=0; $j<$jmlrec; $j++) {
if (strncasecmp($record[$j],"!",1) != 0 ) $updno++;
if ($record[$j] != "" && strncasecmp($record[$j],"!",1) == 0 ) fputs($update_data,substr($record[$j],1));
}
}
fclose($update_data);
I'm looking forward for some ideas. I'll love to invite you for a coffee... ;) I can also send the whole script, if someone is interested.
Best!
Philipp
EDIT: I'm still totally lost in the code, so I want to share the other parts of the code with you and maybe someone finds the problem. ;) Thanks!
$jml_page = intval($jmlrec/$max_entry_per_page);
$sisa = $jmlrec%$max_entry_per_page;
if ($sisa > 0) $jml_page++;
// Set $nomaybe, $nono, $noyes DEBUG
$nomaybe = 0;
$nono = 0;
$noyes = 0;
$countmaybe = 0;
$countno = 0;
$countyes = 0;
$counttotal = 0;
$no = 0;
if ($jmlrec == 0) echo "<tr><td align='center'>Noch keine Einträge.</td></tr>";
$w = 0; //--Color
for ($i=0; $i<$max_entry_per_page; $i++) {
// Find the lowest next possible record.
$no = $jmlrec + 1;
if ($nomaybe < $jmlrec ) $no = $nomaybe + 1;
if ($nono < $no - 1 ) $no = $nono + 1;
if ($noyes < $no - 1 ) $no = $noyes + 1;
// Check this is valid.
do {
while (($no < $jmlrec + 1) && (!isset($record[$no-1]) || $record[$no-1] == "")) { $no++; }
$recno = $no - 1;
$cont = 0;
if ($no < $jmlrec + 1) {
$row = explode("|~~|",$record[$recno]);
$vr = $row[4];
$cont = 0;
if (($vr == "ungesehen" || $vr == "gesehen" || $vr == "unentschlossen") && ($no <= $nomaybe)) $cont = 1;
if (($vr == "abgesagt" ) && ($no <= $nono)) $cont = 1;
if (($vr == "zugesagt" || $vr == "Gastgeber") && ($no <= $noyes)) $cont = 1;
if ($cont == 1) $no++;
}
} while ($cont == 1);
if (isset($record[$recno]) && $record[$recno] != "") {
if ($w==0) {
$warna = $table_content_1a;
$warna2 = $table_content_1b;
$w=1;
} else {
$warna = $table_content_2a;
$warna2 = $table_content_2b;
$w=0;
}
do {
$nomaybe++;
$recno = $nomaybe-1;
$row = explode("|~~|",$record[$recno]);
}
while ($nomaybe <= $jmlrec && $row[4] != "ungesehen" && $row[4] != "gesehen" && $row[4] != "unentschlossen" );
if ($row[4] == "ungesehen" || $row[4] == "gesehen" || $row[4]=="unentschlossen") {
echo "<tr><td>$row[3]</td>";
if (isset($row[2]) && $row[2] != "" ) echo "<td><p>$row[2]</p></td>"; else echo "<td><p></p></td>";
if (isset($row[6]) && $row[6] != "" ) echo "<td><p>$row[6]</p></td>"; else echo "<td><p></p></td>";
$countmaybe++;
}
if ($row[4] == "gesehen") echo "<td><b>gesehen</b></td><td>$row[8]</td>";
if ($row[4] == "unentschlossen") echo "<td><b>unentschlossen</b></td><td>$row[8]</td>";
if ($row[4] == "ungesehen") echo "<td><b>ungesehen</b></td><td></td>";
echo "<td><span class='date'><b> </b></span></td>";
if (isset($row[7]) && ($row[4]=="gesehen" || $row[4]=="unentschlossen" || $row[4]=="ungesehen" ) && $row[7] != "")
echo "<td><span class='comment'><i>$row[7]</i></span></td></tr>"; else echo "<td><span class='comment'></span></td></tr>";
do {
$nono++;
$recno = $nono-1;
$row = explode("|~~|",$record[$recno]);
}
while ($nono <= $jmlrec && $row[4] != "abgesagt" && $row != "gesehen" && $row[5] != "unentschlossen" );
$row = explode("|~~|",$record[$recno]);
if ($row[4] == "abgesagt" ) { echo "<tr><td>$row[3]</td><td><p>$row[6]</p></td><td><b>abgesagt</b></td><td>$row[8]</td>";
echo "<td><span class='date'><b> </b></span></td>";
if (isset($row[7]) && $row[7] != "") echo "<td><span class='comment'><i>$row[7]</i></span></td></tr>"; else echo "<td><span class='comment'></span></td></tr>";
$countno++;
}
do {
$noyes++;
$recno = $noyes-1;
$row = explode("|~~|",$record[$recno]);
} while ($noyes <= $jmlrec && $row[4] != "zugesagt" && $row[4] != "Gastgeber" );
if ($row[4] == "zugesagt" || $row[4] == "Gastgeber" ) {
echo "<tr><td>$row[3]";
if ($row[4] == "Gastgeber") print " (Gastgeber) ";
echo "</td>";
if (isset($row[6]) && $row[6] != "" ) echo "<td><p>$row[6]</p></td>"; else echo "<td><p></p></td>";
echo "<td><b>zugesagt</b></td><td>$row[8]</td>";
if (isset($row[5]) && $row[5] != "") echo "<td><p>$row[5]</p></td>"; else echo "<td><p>1</p></td>";
if (isset($row[7]) && $row[7] != "" ) echo "<td><span class='comment'><i>$row[7]</i></span></td></tr>"; else echo "<td><span class='comment'></span></td></tr>";
$countyes++;
if (isset($row[5]) && $row[5] != "") $counttotal = $counttotal + intval($row[5]);
}
} //--end if
} //--end for
It would appear that updated entries are marked by prepending them with !. This loop appears to only be saving the updates, not every record.
Perhaps there was a typo - fopen with mode "w" will truncate the data file at 0 bytes before writing, if only the updated records are to be written, shouldn't that be mode "a" to append them to the existing file?
It is likely there is also a limit on how large a data file is allowed to grow, make sure you have set it large enough to allow 1000 records.
I have problem that my sms messages are imported with csv, then it is checked if number is ok and how long sms is. My problem is that if text messages is longer then 160 it still enters 1 in databse. But it should start counting, if it is less or equal than 160, it is 1 messages, if it is more than 160 but less or equal than 320 it is two messages and if it is more then it is 3 messages.
Page code is here:
<?php
$link = #mysql_connect("localhost", "admin", "") or die("Error: Database offline.");
mysql_select_db("database", $link);
mysql_query("SET NAMES 'utf8' ", $link);
function detect_type($smstext) {
$type = 0;
$dec_codes = array();
for ($i = 0; $i < strlen($smstext); $i++) {
$symbol = substr($smstext,$i,1);
if (!in_array(ord($symbol), $dec_codes)) { $type = 1; }
}
return $type;
}
$result_array = array();
$unic_numbers = array();
$fp = file_get_contents($_FILES['filename']['tmp_name']);
$fp = str_replace("\r\n", "\n", $fp);
$fp = str_replace("\r", "\n", $fp);
$fp = str_replace("\t", "", $fp);
$rows = explode("\n", $fp);
$imported_rows = 0;
$duplicate_rows = 0;
$error_rows = 0;
$long_rows = 0;
for ($i = 0; $i < sizeof($rows); $i++) {
$data = explode(";", $rows[$i]);
$data[1] = sms_formatNumbers($data[1]); // formating number
$userid = 78;
if(strlen($data[1]) > 9){
if($unic_numbers[$data[1]] != true ){ // unic number check
$unic_numbers[$data[1]] = true;
$imported_rows++;
$fullSMS = iconv("ISO-8859-1","UTF-8", trim($data[2])." ".trim($data[3])." ".trim($data[4]));
if(strlen($fullSMS) > 164){
$long_rows++;
}
if($_POST['action'] == 'send'){
// SMS TEXT
$smstext = str_replace("õ", "ò", $fullSMS);
$smstext = str_replace("Õ", "ò", $smstext);
$type = detect_type($smstext);
// servicegroup
$char2 = substr($data[1], 0, 2);
$char3 = substr($data[1], 0, 3);
$c1 = mysql_query("SELECT * FROM zone_info WHERE country_code = '".$char2."'", $link);
$c2 = mysql_query("SELECT * FROM zone_info WHERE country_code = '".$char3."'", $link);
if (mysql_num_rows($c1) == 1) {
$r = mysql_fetch_array($c1);
$price = $r['price'];
$z = mysql_query("SELECT * FROM zone WHERE id = ".$r['up']."", $link);
$zone = mysql_fetch_array($z);
$zone_id = $zone['id'];
$servicegroup = $zone['servicegroup'];
} else if (mysql_num_rows($c2) == 1) {
$r = mysql_fetch_array($c2);
$price = $r['price'];
$z = mysql_query("SELECT * FROM zone WHERE id = ".$r['up']."", $link);
$zone = mysql_fetch_array($z);
$zone_id = $zone['id'];
$servicegroup = $zone['servicegroup'];
}
require_once("../scripts/number.class.php");
$receiver = "00".$data[1];
$obj = new NumberClass($receiver);
$operator = $obj -> operator_code;
$country = $obj -> code;
$operator_name = $obj -> operator_name;
if(strlen($operator) > 0) {
$er = mysql_query("SELECT * FROM zone_exception WHERE country = ".$country." AND operator = ".$operator."", $link);
if (mysql_num_rows($er) == 1) {
$erand = mysql_fetch_array($er);
$price = $erand['price'];
$servicegroup = $erand['servicegroup'];
}
} else $operator_name = "-";
if ($operator_name == "-") { $servicegroup = $servicegroup; }
else {
if ($operator_name == " First Operator") $servicegroup = "90";
else if ($operator_name == "Second Operator") $servicegroup = "91";
else if ($operator_name == "Third Operator") $servicegroup = "92";
else $servicegroup = $servicegroup;
}
require_once("../core/init.mini.inc.php");
$servicegroup = UserBasedRerouting($receiver, $userid, $operator_name, $servicegroup);
$client_type ='corporative';
$sender = $data[0];
$zone_id = 11;
$client_sms_id = '0';
$client_want_report = '0';
$client_report_url = '';
$amount = 1;
$dt_delaysend = '1970-01-01 00:00:00';
$SMSsent = 0;
$SMStotal = 1;
$smstext_old = $smstext;
while($SMSsent < $SMStotal){
$sql = mysql_query("insert into sms_queue (user_id,client_type,dt_entered,sender,receiver,operator,smstext,sms_type,zone_id,client_sms_id,client_want_report,client_report_url,sms_price,amount,servicegroup,dt_delaysend) values ('$userid','$client_type','".date('Y-m-d H:i:s')."','$sender','$receiver','$operator_name','$smstext',0,'$zone_id','$client_sms_id','$client_want_report','$client_report_url','$price','$amount','$servicegroup','$dt_delaysend')", $link);
$SMSsent++;
}
}
}else{
$duplicate_rows ++;
}
}else{
$error_rows++;
}
}
$result_array['success'] = true;
$result_array['long_sms'] = $long_rows;
$result_array['send_sms'] = $imported_rows;
$result_array['error_sms'] = $error_rows;
$result_array['duplicate_sms'] = $duplicate_rows;
$result_array['action'] = $_POST['action'];
echo json_encode($result_array);
function sms_formatNumbers($number){
$number = (int)$number;
$start_code = (int)substr($number,0,4);
if($start_code < 3780 or $start_code == 3785 or $start_code > 3789){
return $number;
}else{
return '';
}
}
?>
Can someone help me out with that?
Thank you
Try
if(strlen($fullSMS) > 164){
$long_rows = ceil(strlen($fullSMS)/160);
}
instead of
if(strlen($fullSMS) > 164){
$long_rows++;
}