public function Save() { $content = new OpenSms_Model_Content([0 => $this->Key]); if ($content->Id > 0) { $this->Id = $content->Id; } $sql = !$this->Id > 0 ? "insert into " . $this->getTableName() . "(`key`, `type`, `body`, `host`) value('" . StringMethods::MakeSave($this->Key) . "', '" . StringMethods::MakeSave($this->Type) . "', '" . StringMethods::MakeSave($this->Body) . "', '" . StringMethods::MakeSave($this->Host) . "');" : "update " . $this->getTableName() . " set `body` = '" . StringMethods::MakeSave($this->Body) . "'\r\n where `key` = '" . StringMethods::MakeSave($this->Key) . "';"; //die($sql); return OpenSms_Helper_Db::executeNonQuery($sql); }
public function Delete() { $sql = "delete from " . OpenSms::getTableName('contact') . " where id = '" . StringMethods::MakeSave($this->Id) . "'"; //die($sql); if (OpenSms_Helper_Db::executeNonQuery($sql)) { return 'One number deleted'; } else { return 'Error in deleting number'; } }
public function Save() { $sql = "insert into " . OpenSms::getTableName('sms') . "(bulkSMSId, number, message, sender, refId, Status)\r\n\t\t\t\t value('" . StringMethods::MakeSave($this->BulkSMSId) . "', '" . StringMethods::MakeSave($this->Number) . "', '" . StringMethods::MakeSave($this->Message) . "', '" . StringMethods::MakeSave($this->Sender) . "', '" . StringMethods::MakeSave($this->RefId) . "', '" . StringMethods::MakeSave($this->Status) . "');"; OpenSms_Helper_Db::executeNonQuery($sql); if ($this->Id == -1) { $sql = "select MAX(id) as no from `" . OpenSms::getTableName('sms') . "`"; $result = OpenSms_Helper_Db::executeReader($sql); foreach ($result as $r) { $this->Id = $r->no; return $r->no; } } }
public static function GetAll($role = '') { $pageObj = new OpenSms_Model_Page(); $tableName = $pageObj->getTableName(); $sql = "select * from {$tableName}" . (empty($role) ? ';' : " where role = {$role}"); $results = OpenSms_Helper_Db::executeReader($sql); $pages = array(); foreach ($results as $r) { $page = new OpenSms_Model_Page(); $page->copy([$r]); $pages[] = $page; } return $pages; }
public static function getClassDb() { if (self::$db != NULL) { return self::$db; } // set the (optional) options of the PDO connection. in this case, we set the fetch mode to // "objects", which means all results will be objects, like this: $result->user_name ! // For example, fetch mode FETCH_ASSOC would return results like this: $result["user_name] ! // @see http://www.php.net/manual/en/pdostatement.fetch.php $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING); // generate a database connection, using the PDO connector // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ self::$db = new PDO(OpenSms::getSystemSetting(OpenSms::DB_TYPE) . ':host=' . OpenSms::getSystemSetting(OpenSms::DB_HOST) . ';dbname=' . OpenSms::getSystemSetting(OpenSms::DB_NAME), OpenSms::getSystemSetting(OpenSms::DB_USERNAME), OpenSms::getSystemSetting(OpenSms::DB_PASSWORD), $options); return self::$db; }
public function save() { if (!isset($_POST[OpenSms::DB_HOST])) { OpenSms::redirectToAction('index'); } //if installed goto dashboard if ($this->getSystemSetting(OpenSms::INSTALLATION_STATUS)) { OpenSms::redirectToAction('index', 'dashboard'); } //var_dump($_POST);die(); // CREATE $config = new SimpleXmlElement('<settings/>'); $config->{OpenSms::VERSION} = $this->getSystemSetting(OpenSms::VERSION); $config->{OpenSms::SITE_NAME} = $this->getFormData(OpenSms::SITE_NAME); $config->{OpenSms::SITE_URL} = $this->getFormData(OpenSms::SITE_URL); $config->{OpenSms::DB_TYPE} = 'mysql'; $config->{OpenSms::DB_HOST} = $this->getFormData(OpenSms::DB_HOST); $config->{OpenSms::DB_NAME} = $this->getFormData(OpenSms::DB_NAME); $config->{OpenSms::DB_TABLE_PREFIX} = $this->getFormData(OpenSms::DB_TABLE_PREFIX); $config->{OpenSms::DB_USERNAME} = $this->getFormData(OpenSms::DB_USERNAME); $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD); $config->{OpenSms::DB_PASSWORD} = $this->getFormData(OpenSms::DB_PASSWORD); $config->{OpenSms::CURRENT_THEME_KEY} = 'default'; $config->{OpenSms::OPEN_PRICE_PER_UNIT} = $this->getFormData(OpenSms::OPEN_PRICE_PER_UNIT); $config->{OpenSms::OPEN_UNITS_PER_SMS} = $this->getFormData(OpenSms::OPEN_UNITS_PER_SMS); $config->{OpenSms::INSTALLATION_STATUS} = 'installed'; //unlink(OpenSms::SETTINGS_FILE_PATH); $config->saveXML(OpenSms::SETTINGS_FILE_PATH); $this->loadSystemSettings(); //create tables OpenSms_Helper_Db::executeNonQuery($this->getDbScript()); //create admin account $user = $this->loadModel('OpenSms_Model_User'); $user->LoginId = $this->getFormData('admin_username'); $user->Password = $this->getFormData('admin_password'); $user->Role = OpenSms_Model_User::ADMIN; $saved = $user->save(); OpenSms::redirectToAction('complete', 'install', 'admin', [0 => $saved == true ? 1 : 0]); }
public static function getMobileNos() { $sql = "select mobileNo from users where mobileNo <> ''"; $result = OpenSms_Helper_Db::executeReader($sql); $nos = ''; foreach ($result as $r) { $fChar = substr($r->mobileNo, 0, 1); if (trim($r->mobileNo) != '' && ($fChar == '2' || $fChar == '0' || $fChar == '8')) { $nos .= trim($r->mobileNo) . ','; } } return $nos; }
public function Delete() { unset($_COOKIE[$this->cookieName]); $sql = "delete from logins where id = '" . StringMethods::MakeSave($this->Id) . "'"; return OpenSms_Helper_Db::executeNonQuery($sql); }
public static function GetCard($offset, $limit) { $sql = "select * from " . OpenSms::getTableName('cards') . " {$offset}, {$limit}"; $result = OpenSms_Helper_Db::executeReader($sql); $cards = array(); foreach ($result as $r) { $card = new OpenSms_Model_Card(); $card->Id = $r->id; $card->Pin = $r->pin; $card->Unit = $r->unit; $card->IsValid = true; $cards[] = $card; } return $cards; }
public static function GetBulkSMS($loginId, $offset, $limit) { $bulkSMSs = array(); $sql = "select * from " . OpenSms::getTableName('bulksms') . " where loginId = '{$loginId}' ORDER BY id DESC LIMIT {$offset}, {$limit};"; $result = OpenSms_Helper_Db::executeReader($sql); foreach ($result as $r) { $bulkSMS = new OpenSms_Model_BulkSms(); $bulkSMS->Id = $r->id; $bulkSMS->LoginId = StringMethods::GetRaw($r->loginId); $bulkSMS->DateCreated = $r->dateCreated; $bulkSMS->Message = StringMethods::GetRaw($r->message); $bulkSMS->Sender = StringMethods::GetRaw($r->sender); $bulkSMS->Status = StringMethods::GetRaw($r->status); $bulkSMS->Count = $r->count; $bulkSMSs[] = $bulkSMS; } return $bulkSMSs; }
public static function getDb() { return OpenSms_Helper_Db::getClassDb(); }
public static function GetRange($offset, $limit, $loginId = '') { $trans = array(); $sql = "select * from " . OpenSms::getTableName('transactions') . (empty($loginId) ? "" : "where loginId = '{$loginId}'") . " ORDER BY id DESC LIMIT {$offset}, {$limit};"; $result = OpenSms_Helper_Db::executeReader($sql); foreach ($result as $r) { $tran = new OpenSms_Model_Transaction(); $tran->Id = $r->id; $tran->LoginId = StringMethods::GetRaw($r->loginId); $tran->Date = $r->date; $tran->Amount = StringMethods::GetRaw($r->amount); $tran->Unit = StringMethods::GetRaw($r->unit); $tran->Status = StringMethods::GetRaw($r->status); $tran->Description = StringMethods::GetRaw($r->description); $tran->PaymentMethod = StringMethods::GetRaw($r->paymentMethod); $tran->IsValid = StringMethods::GetRaw(TRUE); $tran->Type = $r->type; $tran->Committed = $r->committed; $trans[] = $tran; } return $trans; }