[5143] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class exParticipants |
---|
| 4 | { |
---|
| 5 | protected $participants = array(); |
---|
| 6 | var $lang; |
---|
| 7 | |
---|
| 8 | function exParticipants($lang = false) |
---|
| 9 | { |
---|
| 10 | $this->lang = $lang; |
---|
| 11 | if(!$this->lang['ACCEPTED']) $this->lang['ACCEPTED'] = 'Accepted'; |
---|
| 12 | if(!$this->lang['DECLINED']) $this->lang['DECLINED'] = 'Declined'; |
---|
| 13 | if(!$this->lang['TENTATIVE']) $this->lang['TENTATIVE'] = 'Tentative'; |
---|
| 14 | if(!$this->lang['DELEGATED']) $this->lang['DELEGATED'] = 'Delegated'; |
---|
| 15 | if(!$this->lang['NO ANSWER']) $this->lang['NO ANSWER'] = 'No answer'; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | function setParticipantsByString($pParticipants) |
---|
| 19 | { |
---|
| 20 | $arP = explode(',',trim($pParticipants)); |
---|
| 21 | |
---|
| 22 | foreach($arP as $value) |
---|
| 23 | { |
---|
| 24 | $part = $this->parseParticipantString($value); |
---|
| 25 | |
---|
| 26 | if(empty($part)) continue; |
---|
| 27 | |
---|
| 28 | $this->participants[] = $part; |
---|
| 29 | |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | private function parseParticipantString($pParticipant) |
---|
| 34 | { |
---|
| 35 | $pParticipant = htmlspecialchars_decode($pParticipant); |
---|
| 36 | |
---|
| 37 | $return = array(); |
---|
| 38 | |
---|
| 39 | if(preg_match("(\"[^\"]*\"[ ]*<[^>]*@[^>]*>)", $pParticipant)) |
---|
| 40 | { |
---|
| 41 | $cn = null; |
---|
| 42 | $mail = null; |
---|
| 43 | preg_match ("(\"([^\"]*)\")", $pParticipant, $cn); |
---|
| 44 | preg_match ('(<([^>]*@[^>]*)>)', $pParticipant, $mail); |
---|
| 45 | |
---|
| 46 | if($mail[1]) |
---|
| 47 | $return['mail'] = $mail[1]; |
---|
| 48 | |
---|
| 49 | if($cn[1]) |
---|
| 50 | $return['cn'] = $cn[1]; |
---|
| 51 | |
---|
| 52 | return $return; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | if(preg_match("(<[^>]*@[^>]*>)", $pParticipant)) |
---|
| 56 | { |
---|
| 57 | $mail = null; |
---|
| 58 | preg_match ('(<([^>]*@[^>]*)>)', $pParticipant, $mail); |
---|
| 59 | if($mail[1]) |
---|
| 60 | $return['mail'] = $mail[1]; |
---|
| 61 | |
---|
| 62 | return $return; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if(preg_match("([^ ]*@[^ ]*)", $pParticipant)) |
---|
| 66 | { |
---|
| 67 | $mail = null; |
---|
| 68 | preg_match ('([^ ]*@[^ ]*)', $pParticipant, $mail); |
---|
| 69 | if($mail[0]) |
---|
| 70 | $return['mail'] = $mail[0]; |
---|
| 71 | |
---|
| 72 | return $return; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function setParticipantsBySerializable($pParticipants) |
---|
| 78 | { |
---|
| 79 | |
---|
| 80 | if(!unserialize(base64_decode($pParticipants))) //Compatibilidade com eventos antigos; |
---|
| 81 | $this->setParticipantsByString($pParticipants); |
---|
| 82 | else |
---|
| 83 | $this->participants = unserialize(base64_decode($pParticipants)); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | function getParticipantsView() |
---|
| 87 | { |
---|
| 88 | $return = ''; |
---|
| 89 | |
---|
| 90 | $count = 0; |
---|
| 91 | foreach($this->participants as $k => $v) |
---|
| 92 | { |
---|
| 93 | $exp = ''; |
---|
| 94 | |
---|
| 95 | if($count > 0) |
---|
| 96 | $exp .= '<br />'; |
---|
| 97 | |
---|
| 98 | if($v['cn']) |
---|
| 99 | $exp .= $v['cn'].' - '; |
---|
| 100 | |
---|
| 101 | $exp .= $v['mail'].' '; |
---|
| 102 | |
---|
| 103 | if($v['situation']) |
---|
| 104 | $exp .= '('.$this->lang[$v['situation']].') '; |
---|
| 105 | else |
---|
| 106 | $exp .= '('.$this->lang['NO ANSWER'].')'; |
---|
| 107 | |
---|
| 108 | $count++; |
---|
| 109 | $return .= $exp; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | return $return; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | function getParticipantsMailsString() |
---|
| 116 | { |
---|
| 117 | if(!$this->haveParticipants()) |
---|
| 118 | return ''; |
---|
| 119 | |
---|
| 120 | $return = ''; |
---|
| 121 | |
---|
| 122 | foreach($this->participants as $value) |
---|
| 123 | $return .= $value['mail'].', '; |
---|
| 124 | |
---|
| 125 | return (substr($return,0,-2)); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | function getParticipantsSerializable() |
---|
| 129 | { |
---|
| 130 | return base64_encode(serialize($this->participants)); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function getParticipantsArray() |
---|
| 134 | { |
---|
| 135 | return $this->participants; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | function getParticipantsMailsArray() |
---|
| 139 | { |
---|
| 140 | $return = array(); |
---|
| 141 | |
---|
| 142 | foreach ($this->participants as $value) |
---|
| 143 | $return[] = $value['mail']; |
---|
| 144 | |
---|
| 145 | return $return; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | function insertParticipant($pMail, $pSituation = false, $pCN = false) |
---|
| 150 | { |
---|
| 151 | $this->participants[]['mail'] = $pMail; |
---|
| 152 | |
---|
| 153 | if($pSituation) |
---|
| 154 | $this->participants[]['situation'] = $pSituation; |
---|
| 155 | |
---|
| 156 | if($pCN) |
---|
| 157 | $this->participants[]['cn'] = $pCN; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | function removeParticipant($pMail) |
---|
| 161 | { |
---|
| 162 | $mail = $this->parseParticipantString($pMail); |
---|
| 163 | if(!empty($mail['mail'])) |
---|
| 164 | foreach($this->participants as $key => $value) |
---|
| 165 | if($value['mail'] === $mail['mail']) |
---|
| 166 | unset($this->participants[$key]); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | function updateAttribBySerializable($pParticipants) |
---|
| 170 | { |
---|
| 171 | $participans = unserialize(base64_decode($pParticipants)); |
---|
| 172 | |
---|
| 173 | foreach ($participans as $participant) |
---|
| 174 | { |
---|
| 175 | foreach($this->participants as $key => $value) |
---|
| 176 | { |
---|
| 177 | if($value['mail'] == $participant['mail']) |
---|
| 178 | { |
---|
| 179 | $this->participants[$key]['cn'] = $participant['cn']; |
---|
| 180 | $this->participants[$key]['situation'] = $participant['situation']; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | function updateParticipant($mail,$situation,$cn = false) |
---|
| 188 | { |
---|
| 189 | foreach($this->participants as $key => $value) |
---|
| 190 | { |
---|
| 191 | if(trim($value['mail']) == trim($mail)) |
---|
| 192 | { |
---|
| 193 | $this->participants[$key]['situation'] = $situation; |
---|
| 194 | $this->participants[$key]['cn'] = $cn; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | function haveParticipants() |
---|
| 200 | { |
---|
| 201 | if(count($this->participants) > 0) |
---|
| 202 | return true; |
---|
| 203 | else |
---|
| 204 | return false; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | } |
---|
| 210 | ?> |
---|