ignore and Session bugfix in SoapidioRequestPanel
[spidio.git] / www / includes / SoapidioRequestPanel.class.php
blobd74caa4d438fac28da1bcbe22f53af7c45ed6a19
1 <?php
3 class SoapidioRequestPanel extends QPanel {
4 protected $strFunctionDeclaration;
5 protected $strFunctionName;
6 protected $strFunctionArgumentsArray;
8 protected $objControlsArray;
10 /**
11 * Constructor for this control
12 * @param mixed $objParentObject Parent QForm or QControl that is responsible for rendering this control
13 * @param string $strControlId optional control ID
15 public function __construct($objParentObject, $strControlId = null) {
16 try {
17 parent::__construct($objParentObject, $strControlId);
18 } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
20 $this->strCssClass = 'RequestPanel';
23 /**
24 * Set Function declaration got from PHP Soap client.
26 * @param string $strFunctionDeclaration
28 public function SetFunctionDeclaration($strFunctionDeclaration) {
29 $this->strFunctionDeclaration = $strFunctionDeclaration;
30 $this->ResetControls();
32 if (!is_null($strFunctionDeclaration)) {
33 $this->GenerateControlData();
37 /**
38 * Delete all child controls and refresh control.
41 public function ResetControls() {
42 $this->RemoveChildControls(true);
43 $this->objControlsArray = array();
44 $this->Refresh();
46 /**
48 * Generate the required controls for this FunctionDeclaration.
51 protected function GenerateControlData() {
52 $intArgumentsBegin = strpos($this->strFunctionDeclaration, '(') + 1;
53 $intArgumentsLength = strpos($this->strFunctionDeclaration, ')') - $intArgumentsBegin;
54 $strArguments = substr($this->strFunctionDeclaration, $intArgumentsBegin, $intArgumentsLength);
55 $this->strFunctionArgumentsArray = explode(', ', $strArguments);
57 $intFunctionBegin = strpos($this->strFunctionDeclaration, ' ') + 1;
58 $intFunctionLength = $intArgumentsBegin - $intFunctionBegin - 1;
59 $this->strFunctionName = substr($this->strFunctionDeclaration, $intFunctionBegin, $intFunctionLength);
61 $btnRequest = new QButton($this);
62 $btnRequest->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnRequest_Click'));
63 $btnRequest->Text = $this->strFunctionName;
65 $this->objControlsArray[] = SoapidioRequestPanelElement::TableBegin;
66 for ($i = 0; $i < count($this->strFunctionArgumentsArray); $i++) {
67 $strFunctionArguments = explode(' ', $this->strFunctionArgumentsArray[$i]);
68 if ($strArguments) {
69 $this->objControlsArray[] = SoapidioRequestPanelElement::RowBegin;
71 switch (QType::TypeFromDoc($strFunctionArguments[0])) {
72 case QType::Boolean:
73 $txtControl = new QCheckBox($this);
74 $txtControl->Required = true;
75 $txtControl->AddAction(new QEnterkeyEvent(), new QTerminateAction());
77 $clbControl = new QControlLabel($txtControl);
78 $clbControl->ForControl = $txtControl;
79 $clbControl->Text = sprintf('%s: ', substr($strFunctionArguments[1], 4));
81 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
82 $this->objControlsArray[] = $clbControl;
83 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
85 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
86 $this->objControlsArray[] = $txtControl;
87 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
88 break;
89 case QType::Integer:
90 $txtControl = new QIntegerTextBox($this);
91 $txtControl->Required = true;
92 $txtControl->AddAction(new QEnterkeyEvent(), new QTerminateAction());
94 $clbControl = new QControlLabel($txtControl);
95 $clbControl->ForControl = $txtControl;
96 $clbControl->Text = sprintf('%s: ', substr($strFunctionArguments[1], 4));
98 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
99 $this->objControlsArray[] = $clbControl;
100 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
102 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
103 $this->objControlsArray[] = $txtControl;
104 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
105 break;
106 case QType::String:
107 $txtControl = new QTextBox($this);
108 $txtControl->Required = true;
109 $txtControl->AddAction(new QEnterkeyEvent(), new QTerminateAction());
111 $clbControl = new QControlLabel($txtControl);
112 $clbControl->ForControl = $txtControl;
113 $clbControl->Text = sprintf('%s: ', substr($strFunctionArguments[1], 4));
115 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
116 $this->objControlsArray[] = $clbControl;
117 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
119 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
120 $this->objControlsArray[] = $txtControl;
121 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
122 break;
123 case 'Session':
124 $lstControl = new QListBox($this);
125 $lstControl->Required = true;
126 $lstControl->AddAction(new QEnterkeyEvent(), new QTerminateAction());
128 $dttExpire = new QDateTime(QDateTime::Now);
129 $dttExpire->AddSeconds(-QApplication::GetConfig('session_timeout', QType::Integer));
131 // Query table and delete first timed out sessions for this ip address, delete only when there is no SessionKey assigned (checked via reverse relationship).
132 foreach (Session::QueryArray(
133 QQ::AndCondition(
134 QQ::Equal(QQN::Session()->IpAddress, (string) QApplication::GetClientAddress()),
135 QQ::LessThan(QQN::Session()->Changed, $dttExpire),
136 QQ::IsNull(QQN::Session()->SessionKeyAsSession->Id)
138 ) as $objSession) {
139 $objSession->Delete();
140 QApplication::AddLogEntry(LogItemEnum::SESSIONTIMEOUT);
143 foreach (Session::QueryArray(
144 QQ::AndCondition(
145 QQ::Equal(QQN::Session()->IpAddress, (string) QApplication::GetClientAddress()),
146 QQ::IsNotNull(QQN::Session()->UserId)
148 ) as $objSession) {
149 $lstControl->AddItem($objSession->__toString(), $objSession);
152 if ($lstControl->ItemCount == 0) {
153 $lstControl->AddItem(QApplication::Translate('(no sessions available)'), null);
154 $btnRequest->Enabled = false;
157 $clbControl = new QControlLabel($lstControl);
158 $clbControl->ForControl = $lstControl;
159 $clbControl->Text = sprintf('%s: ', substr($strFunctionArguments[1], 4));
161 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
162 $this->objControlsArray[] = $clbControl;
163 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
165 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnBegin;
166 $this->objControlsArray[] = $lstControl;
167 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
168 break;
171 $this->objControlsArray[] = SoapidioRequestPanelElement::RowEnd;
175 $this->objControlsArray[] = SoapidioRequestPanelElement::RowBegin;
176 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnSpan;
177 $this->objControlsArray[] = $btnRequest;
178 $this->objControlsArray[] = SoapidioRequestPanelElement::ColumnEnd;
179 $this->objControlsArray[] = SoapidioRequestPanelElement::RowEnd;
180 $this->objControlsArray[] = SoapidioRequestPanelElement::TableEnd;
184 * Action handler for request button. It execute on the parent form the pnlRequest_DoRequest() function.
187 public function btnRequest_Click() {
188 $mixArgumentArray = array();
189 foreach ($this->objChildControlArray as $objControl) {
190 if (!($objControl instanceof QButton)) {
191 switch (get_class($objControl)) {
192 case 'QCheckBox':
193 $mixArgumentArray[] = $objControl->Checked;
194 break;
195 case 'QIntegerTextBox':
196 $mixArgumentArray[] = $objControl->Text;
197 break;
198 case 'QTextBox':
199 $mixArgumentArray[] = $objControl->Text;
200 break;
201 case 'QListBox':
202 $mixArgumentArray[] = $objControl->SelectedValue;
203 break;
209 $this->objForm->pnlRequest_DoRequest($this->strFunctionName, $this->strFunctionDeclaration, $mixArgumentArray);
213 * Return HTML for this control.
215 * @return string
217 protected function GetControlHtml() {
218 $strReturn = '';
220 for ($i = 0; $i < count($this->objControlsArray); $i++) {
221 if ($this->objControlsArray[$i] instanceof QControl) {
222 $strReturn .= $this->objControlsArray[$i]->GetControlHtml();
223 } else if (is_int($this->objControlsArray[$i])) {
224 switch ($this->objControlsArray[$i]) {
225 case SoapidioRequestPanelElement::TableBegin:
226 $strReturn .= sprintf('<table class="%s">', $this->strCssClass);
227 break;
228 case SoapidioRequestPanelElement::TableEnd:
229 $strReturn .= '</table>';
230 break;
232 case SoapidioRequestPanelElement::RowBegin:
233 $strReturn .= '<tr>';
234 break;
235 case SoapidioRequestPanelElement::RowEnd:
236 $strReturn .= '</tr>';
237 break;
239 case SoapidioRequestPanelElement::ColumnBegin:
240 $strReturn .= '<td>';
241 break;
242 case SoapidioRequestPanelElement::ColumnEnd:
243 $strReturn .= '</td>';
244 break;
245 case SoapidioRequestPanelElement::ColumnSpan:
246 $strReturn .= '<td colspan="2">';
247 break;
249 } else {
250 throw new QCallerException('Non valid item in array');
254 return $strReturn;
258 * Parse $_POST data for all child controls.
261 public function ParsePostData() {
262 foreach ($this->objChildControlArray as $objControl) {
263 $objControl->ParsePostData();
268 abstract class SoapidioRequestPanelElement {
269 const TableBegin = 1;
270 const TableEnd = 2;
272 const RowBegin = 4;
273 const RowEnd = 8;
275 const ColumnSpan = 16;
276 const ColumnBegin = 32;
277 const ColumnEnd = 64;