diff --git a/system/autoload/User.php b/system/autoload/User.php new file mode 100644 index 0000000..c8b0919 --- /dev/null +++ b/system/autoload/User.php @@ -0,0 +1,202 @@ + $v) { + // if has : then its an installment + if (strpos($v, ":") === false) { + // Not installment + $bills[$k] = $v; + $addcost += $v; + } else { + // installment + list($cost, $rem) = explode(":", $v); + // :0 installment is done + if (!empty($rem)) { + $bills[$k] = $cost; + $addcost += $cost; + } + } + } + return [$bills, $addcost]; + } + + public static function billsPaid($bills, $id = 0) + { + if (!$id) { + $id = User::getID(); + if (!$id) { + return []; + } + } + foreach ($bills as $k => $v) { + // if has : then its an installment + $v = User::getAttribute($k, $id); + if (strpos($v, ":") === false) { + // Not installment, no need decrement + } else { + // installment + list($cost, $rem) = explode(":", $v); + // :0 installment is done + if ($rem != 0) { + User::setAttribute($k, "$cost:" . ($rem - 1), $id); + } + } + } + } + + public static function setAttribute($name, $value, $id = 0) + { + if (!$id) { + $id = User::getID(); + if (!$id) { + return ''; + } + } + $f = ORM::for_table('tbl_customers_fields')->where('field_name', $name)->where('customer_id', $id)->find_one(); + if (!$f) { + $f = ORM::for_table('tbl_customers_fields')->create(); + $f->customer_id = $id; + $f->field_name = $name; + $f->field_value = $value; + $f->save(); + $result = $f->id(); + if ($result) { + return $result; + } + } else { + $f->field_value = $value; + $f->save(); + return $f['id']; + } + return 0; + } + + public static function getAttribute($name, $id = 0) + { + if (!$id) { + $id = User::getID(); + if (!$id) { + return []; + } + } + $f = ORM::for_table('tbl_customers_fields')->where('field_name', $name)->where('customer_id', $id)->find_one(); + if ($f) { + return $f['field_value']; + } + return ''; + } + + public static function getAttributes($endWith, $id = 0) + { + if (!$id) { + $id = User::getID(); + if (!$id) { + return []; + } + } + $attrs = []; + $f = ORM::for_table('tbl_customers_fields')->where_like('field_name', "%$endWith")->where('customer_id', $id)->find_many(); + if ($f) { + foreach ($f as $k) { + $attrs[$k['field_name']] = $k['field_value']; + } + return $attrs; + } + return []; + } + + public static function setCookie($uid) + { + global $db_password; + if (isset($uid)) { + $time = time(); + setcookie('uid', $uid . '.' . $time . '.' . sha1($uid . '.' . $time . '.' . $db_password), time() + 86400 * 30); + } + } + + public static function removeCookie() + { + if (isset($_COOKIE['uid'])) { + setcookie('uid', '', time() - 86400); + } + } + + public static function _info($id = 0) + { + global $config; + if ($config['maintenance_mode'] == true) { + if ($config['maintenance_mode_logout'] == true) { + r2(U . 'logout', 'd', ''); + } else { + displayMaintenanceMessage(); + } + } + if (!$id) { + $id = User::getID(); + } + $d = ORM::for_table('tbl_customers')->find_one($id); + if ($d['status'] == 'Banned') { + _alert(Lang::T('This account status') . ' : ' . Lang::T($d['status']), 'danger', "logout"); + } + if (empty($d['username'])) { + r2(U . 'logout', 'd', ''); + } + return $d; + } + + public static function _billing($id = 0) + { + if (!$id) { + $id = User::getID(); + } + $d = ORM::for_table('tbl_user_recharges') + ->select('tbl_user_recharges.id', 'id') + ->selects([ + 'customer_id', 'username', 'plan_id', 'namebp', 'recharged_on', 'recharged_time', 'expiration', 'time', + 'status', 'method', 'plan_type', + ['tbl_user_recharges.routers', 'routers'], + ['tbl_user_recharges.type', 'type'], + 'admin_id', 'prepaid' + ]) + ->where('customer_id', $id) + ->left_outer_join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id')) + ->find_many(); + return $d; + } +} diff --git a/system/autoload/Validator.php b/system/autoload/Validator.php new file mode 100644 index 0000000..c200a2b --- /dev/null +++ b/system/autoload/Validator.php @@ -0,0 +1,323 @@ += $max) return false; + return true; + } + + /** + * Email addres check + * + * @access public + * @param string $string + * @param array $exclude + * @return bool + */ + public static function Email($string, $exclude = "") + { + if (self::textHit($string, $exclude)) return false; + return (bool)preg_match("/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i", $string); + } + + /** + * URL check + * + * @access public + * @param strin $string + * @return bool + */ + public static function Url($string, $exclude = "") + { + if (self::textHit($string, $exclude)) return false; + return (bool)preg_match("/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i", $string); + } + + /** + * IP + * + * @access public + * @param string $string + * @return void + */ + public static function Ip($string) + { + return (bool)preg_match("/^(1?\d{1,2}|2([0-4]\d|5[0-5]))(\.(1?\d{1,2}|2([0-4]\d|5[0-5]))){3}$/", $string); + } + + /** + * Check if it is an number + * + * @access public + * @param int $integer + * @param int $max + * @param int $min + * @return bool + */ + public static function Number($integer, $max = null, $min = 0) + { + if (preg_match("/^\-?\+?[0-9e1-9]+$/", $integer)) { + if (!self::numberBetween($integer, $max, $min)) return false; + return true; + } + return false; + } + + /** + * Check if it is an unsigned number + * + * @access public + * @param int $integer + * @return bool + */ + public static function UnsignedNumber($integer) + { + return (bool)preg_match("/^\+?[0-9]+$/", $integer); + } + + /** + * Float + * + * @access public + * @param string $string + * @return bool + */ + public static function Float($string) + { + return (bool)($string == strval(floatval($string))) ? true : false; + } + + /** + * Alpha check + * + * @access public + * @param string $string + * @return void + */ + public static function Alpha($string) + { + return (bool)preg_match("/^[a-zA-Z]+$/", $string); + } + + /** + * Alpha numeric check + * + * @access public + * @param string $string + * @return void + */ + public static function AlphaNumeric($string) + { + return (bool)preg_match("/^[0-9a-zA-Z]+$/", $string); + } + + /** + * Specific chars check + * + * @access public + * @param string $string + * @param array $allowed + * @return void + */ + public static function Chars($string, $allowed = array("a-z")) + { + return (bool)preg_match("/^[" . implode("", $allowed) . "]+$/", $string); + } + + /** + * Check length of an string + * + * @access public + * @param string $stirng + * @param int $max + * @param int $min + * @return bool + */ + public static function Length($string, $max = null, $min = 0) + { + $length = strlen($string); + if (!self::numberBetween($length, $max, $min)) return false; + return true; + } + + /** + * Hex color check + * + * @access public + * @param string $string + * @return void + */ + public static function HexColor($string) + { + return (bool)preg_match("/^(#)?([0-9a-f]{1,2}){3}$/i", $string); + } + + /** + * Data validation + * + * Does'nt matter how you provide the date + * dd/mm/yyyy + * dd-mm-yyyy + * yyyy/mm/dd + * yyyy-mm-dd + * + * @access public + * @param string $string + * @return bool + */ + public static function Date($string) + { + $date = date('Y', strtotime($string)); + return ($date == "1970" || $date == '') ? false : true; + } + + /** + * Older than check + * + * @access public + * @param string $string + * @param int $age + * @return bool + */ + public static function OlderThan($string, $age) + { + $date = date('Y', strtotime($string)); + if ($date == "1970" || $date == '') return false; + return (date('Y') - $date) > $age ? true : false; + } + + /** + * XML valid + * + * @access public + * @param string $string + * @return bool + */ + public static function Xml($string) + { + $Xml = @simplexml_load_string($string); + return ($Xml === false) ? false : true; + } + + /** + * Is filesize between + * + * @access public + * @param string $file + * @param int $max + * @param int $min + * @return bool + */ + public static function FilesizeBetween($file, $max = null, $min = 0) + { + $filesize = filesize($file); + return self::numberBetween($filesize, $max, $min); + } + + /** + * Is image width between + * + * @access public + * @param string $image + * @param int $max_width + * @param int $min_width + * @param int $max_height + * @param int $min_height + * @return void + */ + public static function ImageSizeBetween($image, $max_width = "", $min_width = 0, $max_height = "", $min_height = 0) + { + $size = getimagesize($image); + if (!self::numberBetween($size[0], $max_width, $min_width)) return false; + if (!self::numberBetween($size[1], $max_height, $min_height)) return false; + return true; + } + + /** + * Phone numbers + * + * @access public + * @param string $phone + * @return bool + */ + public static function Phone($phone) + { + $formats = array( + '###-###-####', + '####-###-###', + '(###) ###-###', + '####-####-####', + '##-###-####-####', + '####-####', + '###-###-###', + '#####-###-###', + '##########', + '####-##-##-##' + ); + $format = trim(preg_replace("/[0-9]/", "#", $phone)); + return (bool)in_array($format, $formats); + } + + public static function countRouterPlan($plans, $router){ + $n = 0; + foreach ($plans as $plan){ + if($plan['routers'] == $router){ + $n++; + } + } + return $n; + } + + public static function isRouterHasPlan($plans, $router){ + foreach ($plans as $plan){ + if($plan['routers'] == $router){ + return true; + } + } + return false; + } + +} diff --git a/system/autoload/Widget.php b/system/autoload/Widget.php new file mode 100644 index 0000000..0a368c2 --- /dev/null +++ b/system/autoload/Widget.php @@ -0,0 +1,50 @@ +'; + foreach($rows as $row){ + + } + $result .= ''; + } + + public static function columns($cols, $result){ + $c = count($cols); + switch($c){ + case 1: + $result .= '
'; + break; + case 2: + $result .= '
'; + break; + case 3: + $result .= '
'; + break; + case 4: + $result .= '
'; + break; + case 5: + $result .= '
'; + break; + default: + $result .= '
'; + break; + } + + foreach($cols as $col){ + } + $result .= '
'; + } +} \ No newline at end of file