예제 #1
0
 public function SaveUser()
 {
     $unicode = $this->get_unicode();
     if (LEVEL < 4 || $this->data["reqdata"]["ivr"] == '-1' || empty($this->data["reqdata"]["ivr"])) {
         $this->sql = "SELECT `idivr` FROM `user` WHERE `id`=" . USERID;
         $ivr = parent::custom();
         $idivr = $ivr[0]['idivr'];
     } else {
         $idivr = $this->data["reqdata"]["ivr"];
     }
     if (isset($this->data["reqdata"]["apply"])) {
         $apply = 0;
     } else {
         $apply = 1;
     }
     $data = array("username" => $this->data["reqdata"]["username"], "password" => $this->data["reqdata"]["password"], "idparent" => USERID, "type" => 1, "balance" => $this->data["reqdata"]["bal"], "recharge_balance" => $this->data["reqdata"]["bal"], "idivr" => $idivr, "level" => LEVEL - 1, "unicode" => $unicode, "flag" => 1, "idtariff" => $this->data["reqdata"]["tariff"], "apply_setting" => $apply);
     parent::Save($data);
     $id = $this->last;
     if (LOGINTYPE != 0) {
         $this->sql = "UPDATE `user` SET `balance`=`balance`-" . $this->data['reqdata']['bal'] . ",`recharge_balance`=`recharge_balance`-" . $this->data['reqdata']['bal'] . " WHERE `id`='" . USERID . "'";
         parent::custom();
     }
     //Add Tariff in user_tariff table
     /* $tmp1=$this->data["reqdata"]["tariff"];
     		$this->sql="select idtariff,tariff_type from tariff where id_tariffname=".$this->data["reqdata"]["tariff"]."";
     		$tariff=parent::custom();
     		$sql="INSERT INTO user_tariff(`iduser`,`idtariff`,`tariff_type`,`prefix`) values";
     		$q="";
     		foreach($tariff as $val)
     		{
     			if($val["tariff_type"]==1)
     				$col='with_prefix';
     			if($val["tariff_type"]==2)
     				$col='without_prefix';	
     			$this->sql="SELECT $col as `col` FROM switch_settings";
     			$data=parent::custom();
     			$q.="('".$id."','".$val["idtariff"]."','".$val["tariff_type"]."','".$data[0]['col']."'),";		
     		}
     		$q=rtrim($q,',');
     		$this->sql=$sql.$q;
     		parent::custom(); */
     //add balance to payment table
     $payment_date = date("Y-m-d H:i:s");
     $desc = "Payment for account setup  on " . $payment_date . " of balance " . $this->data["reqdata"]["username"];
     $balance = array("iduser" => $id, "amount" => $this->data['reqdata']['bal'], "payment_date" => $payment_date, "description" => $desc, "usertype" => 1, "type" => 1, "flag" => 1, "created_by" => USERID);
     parent::RawSave('payment', $balance, 'id');
     if (LOGINTYPE == 0) {
         $accountcode = $id;
     } else {
         $accountcode = $this->get_account_code($id);
     }
     parent::RawUpdate("user", array("accountcode" => $accountcode), $id, "id");
     $this->response();
 }