Пример #1
0
 /**
  * Gets the JSON representation of this object for use in AJAX calls.
  * @return string The JSON representation of this object.
  */
 public function ToJSON()
 {
     $json = "";
     $json .= "{ ";
     $json .= "\"ID\": " . $this->ID . ", ";
     // $json .= "\"Tenant\": " . $this->Tenant->ToJSON() . ", ";
     // $json .= "\"Module\": " . $this->Module->ToJSON() . ", ";
     $json .= "\"ParentObject\": " . ($this->ParentObject == null ? "null" : $this->ParentObject->ToJSON()) . ", ";
     $json .= "\"Name\": \"" . \JH\Utilities::JavaScriptEncode($this->Name, "\"") . "\"";
     $json .= " }";
     return $json;
 }
Пример #2
0
 /**
  * Creates a TenantObject with the specified criteria on this Tenant.
  * @param string $name The name of the TenantObject to create.
  * @param string $titles
  * @param string $descriptions
  * @param TenantInstanceProperty[] $properties Instance properties to create on this TenantObject.
  * @param TenantObject $parentObject The TenantObject which owns this TenantObject
  * @param string $instances
  * @param TenantObjectInstanceProperty $defaultProperty The TenantObjectInstanceProperty used for inline-rendering an instance of this property
  * @return NULL|\PhoenixSNS\Objects\TenantObject The newly-created TenantObject, or NULL if the creation operation failed.
  */
 public function CreateObject($name, $titles = null, $descriptions = null, array $properties = null, TenantObject $parentObject = null, array $instances = null, TenantObjectInstanceProperty $defaultProperty = null)
 {
     global $MySQL;
     if ($titles == null) {
         $titles = array($name);
     }
     if ($descriptions == null) {
         $descriptions = array();
     }
     if ($properties == null) {
         $properties = array();
     }
     if ($instances == null) {
         $instances = array();
     }
     // do not create the object if the object with the same name already exists
     if ($this->HasObject($name)) {
         $bt = debug_backtrace();
         trigger_error("Object '" . $name . "' already exists on tenant '" . $this->URL . "' in " . $bt[0]["file"] . "::" . $bt[0]["function"] . " on line " . $bt[0]["line"] . "; ", E_USER_WARNING);
         return $this->GetObject($name);
     }
     $query = "INSERT INTO " . System::$Configuration["Database.TablePrefix"] . "TenantObjects (object_TenantID, object_ModuleID, object_ParentObjectID, object_Name, object_DefaultPropertyID) VALUES (";
     $query .= $this->ID . ", ";
     $query .= "NULL" . ", ";
     $query .= ($parentObject == null ? "NULL" : $parentObject->ID) . ", ";
     $query .= "'" . $MySQL->real_escape_string($name) . "', ";
     if ($defaultProperty != null && is_numeric($defaultProperty->ID)) {
         $query .= $defaultProperty->ID;
     } else {
         $query .= "NULL";
     }
     $query .= ")";
     $result = $MySQL->query($query);
     if ($result === false) {
         return false;
     }
     $id = $MySQL->insert_id;
     $object = TenantObject::GetByID($id);
     $object->SetTitles($titles);
     $object->SetDescriptions($descriptions);
     foreach ($properties as $property) {
         $object->CreateInstanceProperty($property);
     }
     if (is_array($instances)) {
         foreach ($instances as $instance) {
             // handle as an array of property/value pairs
             $object->CreateInstance($instance);
         }
     }
     return $object;
 }
 public static function GetByAssoc($values)
 {
     $item = new TenantObjectInstanceMethod();
     $item->ID = $values["method_ID"];
     $item->ParentObject = TenantObject::GetByID($values["method_ObjectID"]);
     $item->Name = $values["method_Name"];
     $item->CodeBlob = $values["method_CodeBlob"];
     return $item;
 }
 /**
  * Creates a new TenantObjectInstanceProperty object based on the given values from the database.
  * @param array $values
  * @return TenantObjectInstanceProperty based on the values of the fields in the given associative array
  */
 public static function GetByAssoc($values)
 {
     $item = new TenantObjectInstanceProperty();
     $item->ID = $values["property_ID"];
     $item->ParentObject = TenantObject::GetByID($values["property_ObjectID"]);
     $item->Name = $values["property_Name"];
     $item->DataType = DataType::GetByID($values["property_DataTypeID"]);
     if ($item->DataType != null) {
         $item->DefaultValue = $item->DataType->Decode($values["property_DefaultValue"]);
     }
     $item->Required = $values["property_IsRequired"] == 1;
     $item->ColumnVisible = $values["property_ColumnVisible"] == 1;
     return $item;
 }
    protected function RenderContent()
    {
        ?>
			<form method="POST" onsubmit="return form_OnSubmit();">
				<?php 
        $tbs = new TabContainer("tbsTabs");
        $tbs->TabPages[] = new TabPage("tabGeneralInformation", "General Information", null, null, null, function () {
            $fv = new FormView();
            $fv->Items[] = new FormViewItemText("txtTenantURL", "tenant_URL", "Name", $this->Tenant->URL);
            $fvTenantTypes = array();
            $tenanttypes = TenantType::Get();
            foreach ($tenanttypes as $tenanttype) {
                $fvTenantType = new FormViewItemChoiceValue($tenanttype->Title, $tenanttype->ID);
                $fvTenantType->Selected = $this->Tenant != null && $this->Tenant->Type != null && $tenanttype->ID == $this->Tenant->Type->ID;
                $fvTenantTypes[] = $fvTenantType;
            }
            $fv->Items[] = new FormViewItemChoice("cboTenantType", "tenant_TypeID", "Type", null, $fvTenantTypes);
            $fv->Items[] = new FormViewItemBoolean("chkStatus", "tenant_Status", "Status", $this->Tenant->Status == TenantStatus::Enabled);
            $fvDataCenters = array();
            $datacenters = DataCenter::Get();
            foreach ($datacenters as $datacenter) {
                $fvDataCenter = new FormViewItemChoiceValue($datacenter->Title, $datacenter->ID);
                $fvDataCenter->Selected = $this->Tenant != null && $this->Tenant->DataCenters->Contains($datacenter);
                $fvDataCenters[] = $fvDataCenter;
            }
            $fv->Items[] = new FormViewItemChoice("cboDataCenter", "tenant_DataCenterIDs", "Data centers", null, $fvDataCenters, true);
            $fvPaymentPlans = array();
            $paymentplans = PaymentPlan::Get();
            foreach ($paymentplans as $paymentplan) {
                $fvPaymentPlan = new FormViewItemChoiceValue($paymentplan->Title, $paymentplan->ID);
                $fvPaymentPlan->Selected = $this->Tenant != null && $this->Tenant->PaymentPlan != null && $paymentplan->ID == $this->Tenant->PaymentPlan->ID;
                $fvPaymentPlans[] = $fvPaymentPlan;
            }
            $fv->Items[] = new FormViewItemChoice("cboPaymentPlan", "tenant_PaymentPlanID", "Payment plan", null, $fvPaymentPlans);
            $fv->Items[] = new FormViewItemDateTime("txtActivationDate", "tenant_BeginTimestamp", "Activation date", $this->Tenant != null ? $this->Tenant->BeginTimestamp : null, true);
            $fv->Items[] = new FormViewItemDateTime("txtTerminationDate", "tenant_EndTimestamp", "Termination date", $this->Tenant != null ? $this->Tenant->EndTimestamp : null, true);
            $fv->Items[] = new FormViewItemMemo("txtDescription", "tenant_Description", "Description", $this->Tenant->Description);
            $fv->Render();
        });
        $path = System::GetVirtualPath();
        if ($path[1] != "clone") {
            $tbs->TabPages[] = new TabPage("tabCustomProperties", "Custom Properties", null, null, null, function () {
                $lv = new ListView();
                $lv->Width = "100%";
                $lv->EnableAddRemoveRows = true;
                $lv->Columns = array(new ListViewColumn("lvcProperty", "Property"), new ListViewColumn("lvcDescription", "Description"), new ListViewColumn("lvcValue", "Value"));
                $properties = $this->Tenant->GetProperties();
                foreach ($properties as $property) {
                    $lv->Items[] = new ListViewItem(array(new ListViewItemColumn("lvcProperty", $property->Name), new ListViewItemColumn("lvcDescription", $property->Description), new ListViewItemColumn("lvcValue", null, null, function ($property) {
                        $property->DataType->RenderEditor($this->Tenant->GetPropertyValue($property), "Property_" . $property->ID);
                    }, $property)));
                }
                $lv->Render();
            });
            $tbs->TabPages[] = new TabPage("tabEnabledModules", "Enabled Modules", null, null, null, function () {
                $lv = new ListView();
                $lv->Width = "100%";
                $lv->EnableRowCheckBoxes = true;
                $lv->Columns = array(new ListViewColumn("lvcModule", "Module"), new ListViewColumn("lvcDescription", "Description"));
                $modules = Module::Get(null);
                foreach ($modules as $module) {
                    $item = new ListViewItem(array(new ListViewItemColumn("lvcModule", "<a href=\"" . System::ExpandRelativePath("~/tenant/modify/" . $this->Tenant->URL . "/modules/" . $module->ID . "\">" . $module->Title . "</a>", $module->Title)), new ListViewItemColumn("lvcDescription", $module->Description)));
                    $item->Checked = $this->Tenant->HasModule($module);
                    $lv->Items[] = $item;
                }
                $lv->Render();
            });
            $tbs->TabPages[] = new TabPage("tabGlobalObjects", "Global Objects", null, null, null, function () {
                $lv = new ListView();
                $lv->Width = "100%";
                $lv->EnableAddRemoveRows = true;
                $lv->Columns = array(new ListViewColumn("lvcObject", "Object"), new ListViewColumn("lvcDescription", "Description"), new ListViewColumn("lvcInstances", "Instances"));
                $objects = TenantObject::Get(null, $this->Tenant);
                foreach ($objects as $object) {
                    $lv->Items[] = new ListViewItem(array(new ListViewItemColumn("lvcObject", $object->Name), new ListViewItemColumn("lvcDescription", $object->Description), new ListViewItemColumn("lvcInstances", "<a href=\"" . System::ExpandRelativePath("~/tenant/modify/" . $this->Tenant->URL . "/objects/" . $object->ID . "/instances") . "\">" . $object->CountInstances() . "</a>")));
                }
                $lv->Render();
            });
        }
        $tbs->SelectedTab = $tbs->TabPages[0];
        $tbs->Render();
        ?>
				<div class="Buttons">
					<input class="Button Default" type="submit" value="Save Changes" />
					<a class="Button" onclick="return nav('/tenant');" href="<?php 
        echo System::ExpandRelativePath("~/tenant");
        ?>
">Cancel</a>
				</div>
			</form>
			<script type="text/javascript">
			var TenantManagementPageMode =
			{
				"Create": 1,
				"Modify": 2
			}
			<?php 
        if ($this->Mode == TenantManagementPageMode::Create) {
            echo "var Mode = TenantManagementPageMode.Create;";
        } else {
            if ($this->Mode == TenantManagementPageMode::Modify) {
                echo "var Mode = TenantManagementPageMode.Modify;";
            }
        }
        ?>
			function form_OnSubmit()
			{
				if (Mode == TenantManagementPageMode.Create)
				{
					var xhr = new XMLHttpRequest();
					var tenantName = document.getElementById('txtTenantURL').value;
					
					xhr.open("GET", "/API/Tenant.php?action=exists&q=" + tenantName, false);
					xhr.send(null);
					
					var obj = JSON.parse(xhr.responseText);
					if (obj.result == "success" && obj.exists)
					{
						Notification.Show("Tenant '" + tenantName + "' already exists", "Please specify a unique tenant name", "Error");
						return false;
					}
				}
				
				Notification.Show("Changes were saved successfully", "Taking you back to the Tenant Management page", "Success");
				return true;
			}
			</script>
			<?php 
    }
 /**
  * Creates a new TenantObjectProperty object based on the given values from the database.
  * @param array $values
  * @return \PhoenixSNS\Objects\TenantObjectProperty based on the values of the fields in the given associative array
  */
 public static function GetByAssoc($values)
 {
     $item = new TenantObjectProperty();
     $item->ID = $values["property_ID"];
     $item->Tenant = Tenant::GetByID($values["property_TenantID"]);
     $item->ParentObject = TenantObject::GetByID($values["property_ObjectID"]);
     $item->Name = $values["property_Name"];
     $item->Description = $values["property_Description"];
     $item->DataType = DataType::GetByID($values["property_DataTypeID"]);
     $item->DefaultValue = $values["property_DefaultValue"];
     $item->Required = $values["property_IsRequired"] == 1;
     $item->Enumeration = TenantEnumeration::GetByID($values["property_EnumerationID"]);
     $item->RequireChoiceFromEnumeration = $values["property_RequireChoiceFromEnumeration"] == 1;
     return $item;
 }
Пример #7
0
             $page->CurrentObject = $object;
             $page->CurrentMethod = $method;
             $page->Render();
             break;
         case "instance":
             $page = new TenantObjectMethodManagementPage();
             $page->CurrentTenant = Tenant::GetByURL($path[0]);
             $page->CurrentObject = TenantObject::GetByID($path[2]);
             $page->CurrentMethod = TenantObjectInstanceMethod::GetByID($path[5]);
             $page->Render();
             break;
     }
     break;
 case "":
     $tenant = Tenant::GetByURL($path[0]);
     $object = TenantObject::GetByID($path[2]);
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $count = $_POST["InstanceProperty_NewPropertyCount"];
         for ($i = $count; $i > 0; $i--) {
             $name = $_POST["InstanceProperty_" . $i . "_Name"];
             $dataType = DataType::GetByID($_POST["InstanceProperty_" . $i . "_DataTypeID"]);
             $defaultValue = $_POST["InstanceProperty_" . $i . "_DefaultValue"];
             $object->CreateInstanceProperty(new TenantObjectInstanceProperty($name, $dataType, $defaultValue));
         }
         System::Redirect("~/tenant/manage/" . $tenant->URL . "/objects/" . $object->ID);
         return true;
     } else {
         $page = new TenantObjectManagementPage();
         $page->CurrentTenant = $tenant;
         $page->CurrentObject = $object;
         $page->Render();