ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPaymentNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 include_once './Services/Mail/classes/class.ilMailNotification.php';
11 include_once 'Services/Mail/classes/class.ilMimeMail.php';
12 
14 {
15  public function __construct()
16  {
18  }
19 
20  public function send()
21  {
22  global $ilDB, $lng, $ilSetting;
23 
24  $customer_array = $this->_getObjectsToRemind();
25 
26  foreach ($customer_array as $user_id=>$objects_array)
27  {
28 
29  $this->initLanguage($user_id);
30  $user_lang = $this->getLanguage() ? $this->getLanguage() : $lng;
31 
32  $this->initMail();
33 
34  $this->setRecipients($user_id);
35  $this->setSubject($this->getLanguageText('payment_reminder_notification_subject'));
36 
37  $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
38  $this->appendBody("\n\n");
39  $this->appendBody($user_lang->txt('bought_objects_expire_soon'));
40  $this->appendBody("\n\n");
41 
42  foreach($objects_array as $key=>$pobject)
43  {
44  $this->appendBody("----------------------------------------------------------------------------------------------");
45  $this->appendBody("\n\n");
46  $this->appendBody($user_lang->txt('title').": ".$objects_array[$key]['object_title']."\n");
47  $this->appendBody($user_lang->txt('access_enddate') .": ".$objects_array[$key]['access_enddate']);
48  $this->appendBody("\n");
49 
50  $this->appendBody("\n\n");
51  }
52 
53  $this->appendBody("----------------------------------------------------------------------------------------------");
54 
55 
56  $this->appendBody($mailbox_link);
57  $this->appendBody("\n\n");
58 
59 
62 
63  $mmail = new ilMimeMail();
64  $mmail->autoCheck(false);
65  $mmail->From('noreply');
66  $mmail->To(ilObjUser::_lookupEmail($user_id));
67 
68  $mmail->Subject($this->getSubject());
69  $mmail->Body($this->getBody());
70  $mmail->Send();
71  }
72  }
73 
74  private function _getObjectsToRemind()
75  {
76  global $ilDB, $ilSetting;
77 
78  $num_days = $ilSetting->get('payment_notification_days');
79  $reminder_date = date("Y-m-d H:i:s", time() + ($num_days * 24 * 60 * 60));
80 
81  $res = $ilDB->queryF('
82  SELECT ps.pobject_id, ps.customer_id, ps.object_title, ps.access_enddate, po.ref_id, po.subtype
83  FROM payment_statistic ps
84  INNER JOIN payment_objects po ON po.pobject_id = ps.pobject_id
85  LEFT JOIN payment_prices pp ON pp.pobject_id = ps.pobject_id
86  WHERE ps.duration > %s
87  AND ps.access_enddate = %s
88  AND po.status > %s
89  AND pp.extension = %s
90  ORDER BY ps.customer_id ASC',
91  array('integer', 'date', 'integer', 'integer'),
92  array(0, $reminder_date, 0 , 1));
93 
94  $counter = 0;
95  $objects = array();
96  $customer_id = NULL;
97  while($row = $ilDB->fetchAssoc($res))
98  {
99  if($customer_id == NULL)
100  {
101  $customer_id = $row['customer_id'];
102  }
103  else if ($customer_id != $row['customer_id'])
104  {
105  $counter = 0;
106  $customer_id = $row['customer_id'];
107  }
108 
109  $objects[$customer_id][$counter]['ref_id'] = $row['ref_id'];
110  $objects[$customer_id][$counter]['pobject_id'] = $row['pobject_id'];
111  $objects[$customer_id][$counter]['customer_id'] = $row['customer_id'];
112  $objects[$customer_id][$counter]['access_enddate'] = $row['access_enddate'];
113  $objects[$customer_id][$counter]['object_title'] = $row['object_title'];
114  $objects[$customer_id][$counter]['subtype'] = $row['subtype'];
115 
116  $counter++;
117  }
118  return $objects;
119  }
120 }
121 ?>