Guest User

Untitled

a guest
Aug 10th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.23 KB | None | 0 0
  1. public function getJoinRS() {
  2.         $join = "SELECT * FROM (SELECT m.ID AS MID, m.UserID, m.GroupID, m.Name, m.SName, " .
  3.                 "m.Mail, g.ID AS GID, g.Name AS GName, g.IsSystem FROM " .
  4.                 "`RS_MailList` AS m JOIN RS_Groups AS g ON m.UserID = g.UserID) as j " .
  5.                 "GROUP BY Mail";
  6.         try {
  7.             $result = $this->_rs->query($join)->fetchAll(PDO::FETCH_ASSOC);
  8.             return $result;
  9.         } catch (PDOException $ex) {
  10.             echo "Error function getJoinRS(): " . $ex->getMessage() . "\n";
  11.             return false;
  12.         }
  13.     }
  14.  
  15. public function items() {
  16.         $rs = $this->getJoinRS();
  17.         foreach($rs as $mail) {
  18.             $sql = "SELECT * FROM (SELECT m.ID AS MID, m.UserID, m.GroupID, m.Name, m.SName, " .
  19.                     "m.Mail, g.ID AS GID, g.Name AS GName, g.IsSystem FROM " .
  20.                     "`RS_MailList` AS m JOIN RS_Groups AS g ON m.UserID = g.UserID) as j " .
  21.                     "WHERE Mail='" .$mail['Mail'] . "' GROUP BY UserID";
  22.             $rs_result = $this->_rs->query($sql)->fetchAll(PDO::FETCH_ASSOC);
  23.             foreach ($rs_result as $alter) {
  24.         $query = "SELECT id FROM `MailData` WHERE eMail = '" . $mail['Mail'] . "'";
  25.                 $rid = $this->_alter->query($query)->fetchAll(PDO::FETCH_ASSOC);
  26.                 $id = (int) $rid[0]['id'];
  27.         $i = 0;
  28.                 $this->_alter->beginTransaction();
  29.                 echo "Transaction for mail address " . $mail['Mail'] . " of UserID " . $alter['UserID'] . " prepare...\n";
  30.                 $t = $this->_alter->prepare("INSERT INTO `SubscriberData` (FirstName, LastName) VALUES (:fname, :lname)");
  31.                 $t->bindParam(':fname', $alter['Name'], PDO::PARAM_STR);
  32.                 $t->bindParam(':lname', $alter['SName'], PDO::PARAM_STR);
  33.                 $t->execute();
  34.                 $i++;
  35.                 $subscriberID = $this->_alter->lastInsertId();
  36.                 $item = $this->_alter->prepare("INSERT INTO `ListItem` (UserID, SubscriberID, MailID, ConfirmHash) VALUES (:userID, :subID, :mailID, :hash)");
  37.                 $hash = md5($alter['Mail']);
  38.                 $item->bindParam(':userID', $alter['UserID'], PDO::PARAM_INT);
  39.                 $item->bindParam(':subID', $subscriberID, PDO::PARAM_INT);
  40.                 $item->bindParam(':mailID', $id, PDO::PARAM_INT);
  41.                 $item->bindParam(':hash', $hash, PDO::PARAM_STR);
  42.                 $item->execute();
  43.                 $i++;
  44.                 $listItemID = $this->_alter->lastInsertID();
  45.                 $sql2 = "SELECT * FROM (SELECT m.ID AS MID, m.UserID, m.GroupID, m.Name, m.SName, " .
  46.                         "m.Mail, g.ID AS GID, g.Name AS GName, g.IsSystem FROM " .
  47.                         "`RS_MailList` AS m JOIN RS_Groups AS g ON m.UserID = g.UserID) as j " .
  48.                         "WHERE MID='" . (int) $alter['MID'] . "' GROUP BY UserID, GID";
  49.                 $rs_group = $this->_rs->query($sql2)->fetchAll(PDO::FETCH_ASSOC);
  50.                 foreach ($rs_group as $g) {
  51.                     $group = $this->_alter->prepare("INSERT INTO `Tags` (nameTag, UserID) VALUES (:name, :userID)");
  52.                     $group->bindParam(':name', $g['GName'], PDO::PARAM_STR);
  53.                     $group->bindParam(':userID', $g['UserID'], PDO::PARAM_INT);
  54.                     $group->execute();
  55.                     $i++;
  56.                     $groupID = $this->_alter->lastInsertId();
  57.                     $tags = $this->_alter->prepare("INSERT INTO `TagsListItem` (ItemID, TagID) VALUES (:item, :tag)");
  58.                     $tags->bindParam(':item', $listItemID, PDO::PARAM_INT);
  59.                     $tags->bindParam(':tag', $groupID, PDO::PARAM_INT);
  60.                     $tags->execute();
  61.                     $i++;
  62.                 }
  63.                 try {
  64.                     echo "Transaction for mail address ". $mail['Mail'] . " of UserID " . $alter['UserID'] . " start. All queries: " .$i. "\n";
  65.                     $this->_alter->commit();
  66.                     echo "Transaction complete\n";
  67.                 } catch (PDOException $ex) {
  68.                     $this->_alter->rollBack();
  69.                     echo "Transaction error: " . $ex->getMessage() . "\n";
  70.                 }
  71.             }
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment