Exemple #1
0
 /**
  * Продляет специализации по ID пользователя
  *
  * @param integer $uid ID пользователя
  * @param boolean $is_autopaid Учитывать только отмеченные для автопродления
  * @param string $period Период продления
  * @param boolean $prolong_only
  * @return string Сообщение об ошибке если есть
  */
 function prolongSpecs($uid, $is_autopaid = false, $period = '1 mon', $prolong_only = false)
 {
     global $DB;
     return;
     // #0022795
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/account.php";
     $account = new account();
     $specs = self::getPaidSpecs($uid, true, $is_autopaid, $prolong_only);
     if (!$specs) {
         return 'Нет специализаций';
     }
     $transaction_id = $account->start_transaction($uid);
     $billing_id = NULL;
     $sum = 0;
     foreach ($specs as $i => $spec) {
         $DB->start();
         $sql = "UPDATE spec_paid_choise SET paid_to = paid_to + '{$period}'::interval\n                    WHERE id = {$spec['id']} AND user_id = {$uid} RETURNING paid_to, (paid_to - '{$period}'::interval) as paid_from";
         if ($res = $DB->query($sql)) {
             $paid_to = pg_fetch_result($res, 0, 0);
             $paid_from = pg_fetch_result($res, 0, 1);
             $descr = 'Продление "' . $spec['name'] . '" до ' . date('d.m.Y', strtotime($paid_to));
             if ($error = $account->Buy($bill_id, $transaction_id, self::OP_PAID_SPEC, $uid, $descr, $descr, 1, 0)) {
                 $DB->rollback();
                 break;
             }
             if ($DB->commit()) {
                 $billing_id = $bill_id;
                 $sum++;
                 $sql = "INSERT INTO spec_paid_acc_operations (billing_id, paid_from, paid_to)\n                            VALUES ({$bill_id}, '{$paid_from}'::timestamp, '{$paid_to}'::timestamp)";
                 $rs = $DB->query($sql);
             }
         }
     }
     if ($billing_id) {
         $account->commit_transaction($transaction_id, $uid, $billing_id);
         require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/smail.php";
         require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/op_codes.php";
         $mail = new smail();
         $ops = new op_codes();
         $price = $ops->getCodes(self::OP_PAID_SPEC);
         if ($price) {
             $price = $price[self::OP_PAID_SPEC];
             $mail->PaidSpecsAutopayed($uid, $sum * $price['sum']);
         }
     }
     return $error;
 }