i'm writing a php web script with mvc, but i'm concerned about code is safe.
i fear most "eval($str)", but i try a lot of php function string but nothing happened.
$a = func_get_args();
if((func_num_args()-1)%2 == 0){
$str = "";
array_shift($a);
for($i = 0;$i<sizeof($a);$i++){
if($i%2==0){
if(!is_numeric($a[$i])){
if($a[$i] == 'filter'){
$filter=1;
}
$str.= "$".stripslashes($a[$i])." = ";
}else{
$str.= 'page';
}
}else{
if($filter != 1){
if(is_numeric($a[$i])){
$str.= stripslashes($a[$i]).";";
}else{
$str.=1;
}
}else{
$arr = explode("-",$a[$i]);
$dizz = 'array(';
for($j=0;$j<sizeof($arr);$j++){
if(($j%2)==0){
$dizz .= '\''.stripslashes($arr[$j]).'\'=>';
}else{
$dizz .= '\''.stripslashes($arr[$j]).'\',';
}
}
$dizz = rtrim($dizz,',');
$dizz .= ');';
$str.= $dizz;
}
}
}
eval($str);
}
$filter = isset($filter) ? $filter : false;
$page= isset($page) ? $page: '';
$count= isset($count) ? $count: '';
if($count == ''){
switch ($process) {
case 'table':
$count = 40;
break;
case 'detailed':
$count = 3;
break;
case 'mobile':
$count = 12;
break;
default:
$count = '';
break;
}
}
if($count != ''){
if(is_numeric($count )){
if($count <=200 && $count >0){
$count = $count ;
}else{
$count = 40;
}
}else{
$count = 1;
}
}
if(!is_numeric($page)){
$page= 1;
}
to sql query->
$new_filter = "Where ";
if($filter){
foreach ($filteras $key => $value) {
$new_filter .= 'k.'.$key.'='.$value.' and ';
}
$new_filter = rtrim($new_filter,' and ');
$filter= $new_filter;
}else{
$filter= '';
}
$limit = ($limit) ? 'LIMIT 30' : '';
if($id == ''){
$where = $filter;
}else{
$where = $id;
}
$query = 'select * from kullanici as k join kisiler as ki on k.id = ki.kullanici_id join iletisim as i on k.id = i.kullanici_id '.$where.' '.$siralama.' '.$limit;
$query = $this->_db->prepare($query);
$query->execute();
example url:
profile/show/mobile/page/4/count/5/filter/echo-"'xzcxza'"-sadas-asdxc
this results:
$page = 4;$count= 5;$filter= array('echo'=>'%22%27xzcxza%27%22','sadas'=>'asdxc');
Related
I have an attendance system where users could go in and out the campus, I finished it with this condition:
if($i == 0){
$in = '✔';
$out = '';
}
if($i > 0){
if (strtotime(substr($arr[$i][0],0,10)) == strtotime(substr($arr[$i-1][0],0,10))) {
$count++;
if($count % 2 == 0){
$in = '✔';
$out = '';
}
else{
$in = '';
$out = '✔';
}
}
else{
$count = 0;
$in = '✔';
$out = '';
}
}
However, I was instructed to add a break-in and break-out.
I'm using a hardware wherein it has a database on MS SQL. The types set are:
Type = 1 is In, Type = 2 is Out, Type = 4 is Break Out, and Type = 8 is Break In.
I'm trying to get it using this:
$query = 'SELECT ActualTime, Type FROM TA3.dbo.TimeLogs WHERE TimeLogs.EmployeeID='.$passed.' ORDER BY TimeLogs.ActualTime
$stmt = $conn->query($query);
$stmt->execute();
$arr = $stmt->fetchAll();
if (isset($_POST['Type'])
{
$Type = $_POST['Type'];
}
if($Type == 1)
{
$in = '✔';
$bin = '';
$bout = '';
$out = '';
}
if($Type == 2)
{
$in = '';
$bin = '';
$bout = '';
$out = '✔';
}
if($Type == 4)
{
$in = '';
$bin = '';
$bout = '✔';
$out = '';
}
if($Type == 8)
{
$in = '';
$bin = '✔';
$bout = '';
$out = '';
}
else
{
$in = '✔';
$bin = '';
$bout = '';
$out = '';
}
However, I'm not getting any checks on my table.
I have some issues with a dynamic query:
$cond = array();
if (!empty($type_contrat)) {
$cond[] = "job_offers.type_contrat = '$type_contrat'";
}
if (!empty($categorie_poste)) {
$cond[] = "job_offers.cat_poste = '$categorie_poste'";
}
if (!empty($niveau_etudes)) {
$cond[] = "job_offers.qualifications = '$niveau_etudes'";
}
if (!empty($experience)) {
$cond[] = "job_offers.experience >= '$experience'";
}
if (count($cond)) {
$query = $mysqli->query('SELECT
job_offers.ref_org,
job_offers.titre,
job_offers.qualifications,
job_offers.experience,
job_offers.cat_poste,
job_offers.type_contrat,
job_offers.taux_occupation,
job_offers.lieu_affectation,
job_offers.pays,
job_offers.url,
job_offers.date_entered,
job_offers.date_expire,
organisations.ref_org,
organisations.name_organisation
FROM job_offers,organisations
WHERE job_offers.ref_org = organisations.ref_org AND ');
$query .= implode(' AND ', $cond);
}
print_r($query);
--> result: prints only (linebreaks added for readability):
job_offers.type_contrat = '1' AND
job_offers.cat_poste = '3' AND
job_offers.qualifications = '2' AND
job_offers.experience >= '1'
and therefore no result.
You are trying to append a string to a mysqli-result object...
Check the returnvalue of the mysqli->result() function here.
Since someone is keen on removing this answer; here's your solution:
$cond = array();
if (!empty($type_contrat)) {
$cond[] = "job_offers.type_contrat = '$type_contrat'";
}
if (!empty($categorie_poste)) {
$cond[] = "job_offers.cat_poste = '$categorie_poste'";
}
if (!empty($niveau_etudes)) {
$cond[] = "job_offers.qualifications = '$niveau_etudes'";
}
if (!empty($experience)) {
$cond[] = "job_offers.experience >= '$experience'";
}
if (count($cond)) {
$query = $mysqli->query('SELECT
job_offers.ref_org,
job_offers.titre,
job_offers.qualifications,
job_offers.experience,
job_offers.cat_poste,
job_offers.type_contrat,
job_offers.taux_occupation,
job_offers.lieu_affectation,
job_offers.pays,
job_offers.url,
job_offers.date_entered,
job_offers.date_expire,
organisations.ref_org,
organisations.name_organisation
FROM job_offers,organisations
WHERE job_offers.ref_org = organisations.ref_org AND '.implode(' AND ', $cond));
}
print_r($query);
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
This module takes the articles from categories in joomla and displays them like a blog (short of). the problem is when i click on the title it gives a &view=item&layout=edit&sliderid=1&id=2. non friendly, and the link opens the article in my home page. how to make it produce the correct SEF link like suppose to do? I use joomla 3 and mod_rewrite is enabled
Here is the code:
defined('_JEXEC') or die('Restricted access');
require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
class PBHSourceJcontent {
public $arg;
public function loadFromDB($itemId = -1) {
$myQuery = 'SELECT
i.*
FROM #__content as i
WHERE 1=1
AND i.state = 1';
if ($itemId < 0 && !empty($this->arg['categories'])) {
$myQuery .= ' AND i.catid IN (' .implode(',',$this->arg['categories']). ')';
}
if ($this->arg['ordering'] == 'random' && !empty($this->arg['loaded_items'])) {
$myQuery .= ' AND i.id NOT IN ('.implode(',',$this->arg['loaded_items']).')';
}
if ($itemId < 0 && !empty($this->arg['ordering'])) {
switch ($this->arg['ordering']) {
case 'title_asc':
$myQuery .= ' ORDER BY i.title ASC';
break;
case 'title_desc':
$myQuery .= ' ORDER BY i.title DESC';
break;
case 'date_asc':
$myQuery .= ' ORDER BY i.publish_up ASC';
break;
case 'hits_desc':
$myQuery .= ' ORDER BY i.hits DESC';
break;
case 'hits_asc':
$myQuery .= ' ORDER BY i.hits ASC';
break;
case 'article_order':
$myQuery .= ' ORDER BY i.ordering ASC';
break;
case 'random':
$myQuery .= ' ORDER BY RAND()';
break;
default:
$myQuery .= ' ORDER BY i.publish_up DESC';
break;
}
}
if ($itemId < 0 && !empty($this->arg['items_number'])) {
$myQuery .= ' LIMIT ' . $this->arg['items_number'];
}
if ($itemId < 0 && !empty($this->arg['items_offset']) && $this->arg['items_offset'] > 0 && $this->arg['ordering'] != 'random') {
$myQuery .= ' OFFSET ' . $this->arg['items_offset'];
}
if ($itemId < 0) {
return DMHData::loadObjectList($myQuery);
} else {
$myQuery .= ' AND i.id = ' . $itemId;
return DMHData::loadObject($myQuery);
}
}
public function getItemId($item) {
return $item->id;
}
public function getItemUrl($item) {
if ($this->arg['previewpopup'] == 'enabled') {
$myLink = 'href="#" onclick="DMPinboard.getPreview('.$item->id.');return false;"';
} else {
$link = 'index.php?option=com_content&view=article&id='.$item->id;
$link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
$myLink = 'href="'.urldecode($link).'"';
}
return $myLink;
}
public function getItemTitle($item) {
if ($this->arg['show_title'] == 'yes') {
return $item->title;
} else {
return '';
}
}
public function getItemImage($item) {
if ($this->arg['show_image'] == 'fromtext') {
$myImage = '';
$output = preg_match( '/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $item->introtext, $matches);
if ($output > 0) {
$myImage = $matches[1];
}
return $myImage;
} else if($this->arg['show_image'] == 'introimg') {
$images = json_decode($item->images);
return $images->image_intro;
} else if ($this->arg['show_image'] == 'fullimg') {
$images = json_decode($item->images);
return $images->image_fulltext;
} else {
return '';
}
}
public function getItemIntro($item) {
if ($this->arg['show_intro'] == 'yes') {
$outText = str_replace(array("\t","\n","\r","\r\n"),'',strip_tags($item->introtext));
if (!empty($this->arg['introlength']) && $this->arg['introlength'] > 0) {
$outText = PBHHtml::shorter($outText, $this->arg['introlength']);
}
return $outText;
} else {
return '';
}
}
public function getPreviewImage($item) {
if ($this->arg['show_popup_images'] == 'fromtext') {
$myImage = '';
$output = preg_match('/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $item->introtext, $matches);
if ($output > 0) {
$myImage = $matches[1];
}
return $myImage;
} else if ($this->arg['show_popup_images'] == 'fullimg') {
$images = json_decode($item->images);
return $images->image_fulltext;
} else {
return '';
}
}
public function getPreviewTitle($item) {
if ($this->arg['show_popup_title'] == 'linked') {
$link = 'index.php?option=com_content&view=article&id='.$item->id;
$link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
return ''.$item->title.'';
} else if ($this->arg['show_popup_title'] == 'yes') {
return $item->title;
} else {
return '';
}
}
public function getPreviewContent($item) {
if ($this->arg['show_popup_intro'] == 'withoutimg') {
$outText = preg_replace('/<img[^>]+\>/i', '', $item->introtext);
} else if($this->arg['show_popup_intro'] == 'yes') {
$outText = preg_replace_callback('/(src=["\'])([^"\']+)(["\'])/','PBHHtml::checkImgSrc',$item->introtext);
} else {
$outText = '';
}
if (!empty($this->arg['previewlength']) && $this->arg['previewlength'] > 0) {
$outText = PBHHtml::truncate_teaser($outText,$this->arg['previewlength']);
}
return $outText;
}
public function getPreviewReadmore($item) {
if ($this->arg['show_popup_articlelink'] == 'yes') {
$link = 'index.php?option=com_content&view=article&id='.$item->id;
$link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
return ''.JText::_('COM_DMPINBOARD_FRONTEND_READMORE').'';
} else {
return '';
}
}
public function getShareInfo($item) {
$share = array();
//---
$link = 'index.php?option=com_content&view=article&id='.$item->id;
$link = ContentHelperRoute::getArticleRoute($item->id, $item->catid);
$share['url'] = urldecode(JUri::base().$link);
//---
$share['title'] = $item->title;
return $share;
}
}
?>
I am assuming you mean to output a SEF url in the second part of the getItemUrl($item) function.
Simply
$link = JRoute::_('index.php?option=com_content&view=article&id='.$item->id);
will do. However in your question, above your code, you show &view=item&layout=edit&sliderid=1&id=2 which is not the url in the code below, and will not take you to the article view.
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++;
}