function Render() { global $REQUESTTYPES; echo "<table id='".$this->uniqueID."' class='boxtable'>\n"; echo " <tr>\n"; echo " <th colspan='6'>".$this->title."</th>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <th>date</th>\n"; echo " <th>user</th>\n"; echo " <th>item</th>\n"; echo " <th>request</th>\n"; echo " <th>details</th>\n"; echo " <th> </th>\n"; echo " </tr>\n"; foreach($this->requests as $r) { echo " <tr>\n"; echo " <td>".$r->requestDate."</td>\n"; echo " <td>".$r->user->PrintLinkedAvatar()." ".$r->user->PrintLinkedName()."</td>\n"; echo " <td>".$r->itemType.": "; switch ($r->itemType) { case "prod": if ($r->prod) echo $r->prod->RenderSingleRowShort(); } echo "</td>\n"; echo " <td>".$REQUESTTYPES[$r->requestType]::Describe()."</td>\n"; echo " <td>"; $data = unserialize($r->requestBlob); global $REQUESTTYPES; if ($REQUESTTYPES[$r->requestType]) echo $REQUESTTYPES[$r->requestType]::Display($r->itemID,$data); echo "</td>\n"; echo "<td>"; printf("<form action='%s' method='post' enctype='multipart/form-data'>\n",_html(selfPath())); $csrf = new CSRFProtect(); $csrf->PrintToken(); printf(" <input type='hidden' name='requestID' value='%d'/>",$r->id); printf(" <input type='submit' name='requestAccept' value='accept !'/>"); printf(" <input type='submit' name='requestDeny' value='deny !'/>"); printf(" <input type='hidden' name='%s' value='%s'/>\n",PouetFormProcessor::fieldName,"adminModReq"); printf("</form>\n\n\n"); echo "</td>\n"; echo " </tr>\n"; } echo "</table>\n"; ?> <script type="text/javascript"> <!-- document.observe("dom:loaded",function(){ $$("#pouetbox_adminreq input[type='submit']").invoke("observe","click",function(e){ e.element().setAttribute("clicked","true"); }); $$("#pouetbox_adminreq form").invoke("observe","submit",function(e){ e.stop(); var reqAction = e.element().select("input[type='submit'][clicked='true']").first().name; var reason = null; if (reqAction == "requestDeny") { reason = prompt("Enter the reason why you want to deny this request"); if (reason == null || !reason.length) return; } e.element().select("input[type='submit']").invoke("setAttribute","disabled",true); var opt = Form.serializeElements( e.element().select("input[type='hidden']"), {hash:true} ); opt["partial"] = true; opt["comment"] = reason; opt[ reqAction ] = true; new Ajax.Request( e.element().action, { method: e.element().method, parameters: opt, onSuccess: function(transport) { if (transport.responseJSON.success) { e.element().up("tr").remove(); fireSuccessOverlay( transport.responseJSON.success == "accepted" ? "request accepted !" : "request denied !"); } else { fireErrorOverlay( transport.responseJSON.errors.join("<br/>") ); } } }); }); }); //--> </script> <? }
function Display() { $showBox = true; if (count($this->errors)) { $msg = new PouetBoxModalMessage( true ); $msg->classes[] = "errorbox"; $msg->title = "An error has occured:"; $msg->message = "<ul><li>".implode("</li><li>",$this->errors)."</li></ul>"; $msg->Render(); } else { if ($_POST[ self::fieldName ] && $this->objects[$_POST[ self::fieldName ]]) { $msg = new PouetBoxModalMessage( true ); $msg->classes[] = "successbox"; $msg->title = "Success!"; if ($this->successURL) $msg->message = "<a href='"._html($this->successURL)."'>".$this->successMessage."</a>"; else $msg->message = "<a href='".POUET_ROOT_URL."'>go back to the front page</a>"; $msg->Render(); $showBox = false; } } if ($showBox) { foreach($this->objects as $key=>$object) { $object->Load(); if ($this->renderForm) { printf("<form action='%s' method='post' enctype='multipart/form-data'>\n",_html(selfPath())); $csrf = new CSRFProtect(); $csrf->PrintToken(); } $object->Render(); if ($this->renderForm) { printf(" <input type='hidden' name='%s' value='%s'/>\n",self::fieldName,_html($key)); printf("</form>\n\n\n"); } } } }