/** * Given an id for an agent, get the relationships for that agent, marked up as html for display. * * @param agentid, the id for the agent for which to find relationships. * @return an html list of agent relationships. */ public function getRelationsForAgent($agentid) { global $clientRoot; $result = ""; $result .= "<li><h3>Relationships</h3></li>"; $link = ""; if ($this->isAgentEditor()) { $link .= "<a id='addAgentRelationLink'>Add</a>\n"; } $result .= "<div id='addAgentRelationDiv'>{$link}</div>\n"; $result .= "<div id='addedAgentRelationDiv'></div>\n"; if ($this->isAgentEditor()) { $result .= "\n <script type='text/javascript'>\n function handlerAddRelation () {\n \$.ajax({\n type: 'GET',\n url: '{$clientRoot}/agents/rpc/handler.php',\n data: 'mode=create&table=AgentRelations&fromagentid=" . $agentid . "',\n dataType : 'html',\n success: function(data){\n \$('#addedAgentRelationDiv').html(data);\n },\n error: function( xhr, status, errorThrown ) {\n \$('#statusDiv').html('Error. ' + errorThrown);\n console.log( 'Error: ' + errorThrown );\n console.log( 'Status: ' + status );\n console.dir( xhr );\n }\n });\n return false; \n };\n \$('#addAgentRelationLink').bind('click',handlerAddRelation);\n </script>\n "; } $r = new agentrelations(); $frelations = $r->loadArrayByfromagentid($agentid); if (count($frelations) > 0) { $rView = new agentrelationsView(); $result .= "<ul>"; foreach ($frelations as $relation) { $rView->setModel($relation); $result .= '<li>' . $rView->getSummaryLine($this->isAgentEditor(), false) . '</li>'; } $result .= "</ul>"; } $trelations = $r->loadArrayBytoagentid($agentid); if (count($trelations) > 0) { $rView = new agentrelationsView(); $result .= "<ul>"; foreach ($trelations as $relation) { $rView->setModel($relation); $result .= '<li>' . $rView->getSummaryLine($this->isAgentEditor(), true) . '</li>'; } $result .= "</ul>"; } return $result; }
function editAgentRelations($al) { $result = ""; $am = new AgentManager(); if ($am->isAgentEditor()) { if ($al == null) { $result = "Error: No agent relationship object found."; } else { $alview = new agentrelationsView(); $alview->setModel($al); $result = $alview->getEditFormView(); } } else { $result = "You aren't authorized to edit agent records."; } return $result; }