|
|
@@ -0,0 +1,1470 @@
|
|
|
+<?php
|
|
|
+use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
+if (!defined("WHMCS")) {
|
|
|
+ die("This file cannot be accessed directly");
|
|
|
+}
|
|
|
+function nextcloud_ConfigOptions() {
|
|
|
+
|
|
|
+ global $whmcs;
|
|
|
+ $productid = (int) $_REQUEST['id'];
|
|
|
+
|
|
|
+ foreach(Capsule::table('tbladdonmodules')->where('module', 'nextcloud')->whereIn('setting', array('licensekey','nextcloudLicenseStatus'))->get() as $dataLicenseKey){
|
|
|
+ $stValue = $dataLicenseKey->setting;
|
|
|
+ $$stValue = $dataLicenseKey->value;
|
|
|
+ }
|
|
|
+ $updatedUserCount = Capsule::table('tblproducts')->where('id', $productid)->update(['configoption1' => $licensekey,]);
|
|
|
+ $configValues = Capsule::table('tblproducts')->where('id', $productid)->get();
|
|
|
+ $configValues = (array) $configValues[0];
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Fetch nextcloud Groups* Starts
|
|
|
+ */
|
|
|
+ $nextcloudLicenseStatus = 'Active';
|
|
|
+
|
|
|
+ $servername = $configValues['configoption7'];
|
|
|
+
|
|
|
+
|
|
|
+ $serverDetailsQuery = Capsule::table('tblservers')->where('name', $servername)->where('type', 'nextcloud')->get();
|
|
|
+ $serverDetails = (array) $serverDetailsQuery[0];
|
|
|
+
|
|
|
+ $apiurl = $configValues['configoption3'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+
|
|
|
+ if ($serverDetails['secure'] == 'on') {
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ } else {
|
|
|
+ $serverSecure = 'http://';
|
|
|
+ $decryptedpassword = html_entity_decode(decrypt($serverDetails['password']));
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $serverDetails["hostname"], $apiurl, $configValues["configoption5"]);
|
|
|
+ $response = nextcloud_Send($href, $serverDetails["username"], $decryptedpassword, 'get');
|
|
|
+ }
|
|
|
+
|
|
|
+ $groups = array();
|
|
|
+
|
|
|
+ if ($response->ocs->meta->status == 'ok') {
|
|
|
+ foreach ($response->ocs->data->groups as $key => $value):
|
|
|
+ $groups[] = $value;
|
|
|
+ endforeach;
|
|
|
+ unset($groups[array_search("admin", $groups)]);
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ *
|
|
|
+ * Fetch nextcloud Groups* Ends
|
|
|
+ *
|
|
|
+ */
|
|
|
+ $create_configurationoptions = empty($configValues['configoption12']) ? false : true;
|
|
|
+ //nextcloud_addCustomfieldsConfigurableFields($productid, $create_configurationoptions, $configValues['configoption14'], $configValues['configoption15'], $configValues['configoption17'], $groups);
|
|
|
+ nextcloud_addCustomfieldsConfigurableFields($productid, true, "GB", false, $configValues['configoption17'], $groups);
|
|
|
+
|
|
|
+ $optionsresult = nextcloud_customfieldsConfigurableOptions($productid);
|
|
|
+ if ($optionsresult['result'] == 'success') {
|
|
|
+ if ($optionsresult['availoptions'] == 0)
|
|
|
+ $options = '-- No options --';
|
|
|
+ else
|
|
|
+ $options = $optionsresult['options'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $quotaunitdescription = "";
|
|
|
+ if (!is_numeric($configValues['configoption10']) && !empty($configValues['configoption10'])) {
|
|
|
+ Capsule::table('tblproducts')->where('id', $productid)->update(['configoption10' => '']);
|
|
|
+ $redirect = true;
|
|
|
+ }
|
|
|
+ $quotaType = "text";
|
|
|
+ $quotaFriendlyName = "Quota in GB ";
|
|
|
+ $quotaOptions = "";
|
|
|
+ $quotaDescription = "Please enter value for Quota in Gigabytes";
|
|
|
+
|
|
|
+ $configarray = array(
|
|
|
+ /*
|
|
|
+ "nextcloudApiURL" => array(# nextcloud Api Fields 1
|
|
|
+ "FriendlyName" => "API URL",
|
|
|
+ "Type" => "text",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='nextcloud API URL(For developer only)'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ "Default" => "/ocs/v2.php/cloud/",
|
|
|
+ ),
|
|
|
+ */
|
|
|
+ /*
|
|
|
+ "fetchGroups" => array(# nextcloud Api Fields 2
|
|
|
+ "FriendlyName" => "Group API",
|
|
|
+ "Type" => "text",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='nextcloud API to synchronize nextcloud groups(For developer only)'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ "Default" => "/groups",
|
|
|
+ ),
|
|
|
+ */
|
|
|
+ "serverName" => array(# nextcloud Api Fields 3
|
|
|
+ "FriendlyName" => "Server Name",
|
|
|
+ "Type" => "text",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='Server name which you have configured for nextcloud module'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+ "autonextcloudLogin" => array(# nextcloud Api Fields 4
|
|
|
+ "FriendlyName" => "Login Button",
|
|
|
+ "Type" => "text",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='Text value to show on Auto login nextcloud button in clientarea'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+
|
|
|
+ "nextcloudUsername" => array(# Clientarea Fields 1
|
|
|
+ "FriendlyName" => "Username",
|
|
|
+ "Type" => "dropdown",
|
|
|
+ "Size" => "35",
|
|
|
+ "Options" => $options,
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='Customfield for nextcloud account username'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+ "nextcloudQuota" => array(# Clientarea Fields 4
|
|
|
+ "FriendlyName" => $quotaFriendlyName,
|
|
|
+ "Type" => $quotaType,
|
|
|
+ "Size" => "28",
|
|
|
+ "Options" => $quotaOptions,
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='$quotaDescription'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ //"Default" => $quotaDefault,
|
|
|
+ ),
|
|
|
+
|
|
|
+ "nextcloudPassword" => array(# Clientarea Fields 2
|
|
|
+ "FriendlyName" => "Password",
|
|
|
+ "Type" => "dropdown",
|
|
|
+ "Size" => "35",
|
|
|
+ "Options" => $options,
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='Customfield for nextcloud account password'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+ /*
|
|
|
+ "nextcloudGroup" => array(# Clientarea Fields 3
|
|
|
+ "FriendlyName" => $groupFriendlyName,
|
|
|
+ "Type" => $groupType,
|
|
|
+ "Size" => "35",
|
|
|
+ "Options" => $groupOptions,
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='" . $groupDescription . "'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+ */
|
|
|
+ /*
|
|
|
+ "cloudEncoding" => array(# nextcloud Character Settings Field
|
|
|
+ "FriendlyName" => "Encoding",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "Character Encoding",
|
|
|
+ "Default" => "Example",
|
|
|
+ ),
|
|
|
+ "quotaManageAdmin" => array(# nextcloud Quota Settings Field
|
|
|
+ "FriendlyName" => "Manage Quota",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "Allow admin to manage Quota <span></span>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+
|
|
|
+ "groupManageAdmin" => array(# nextcloud Quota Settings Field
|
|
|
+ "FriendlyName" => "Manage Group",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "Allow admin to manage user group <span></span>",
|
|
|
+ #"Default" => "Example",
|
|
|
+ ),
|
|
|
+ "quotaunits" => array(
|
|
|
+ "FriendlyName" => "Quota Units",
|
|
|
+ "Type" => "dropdown",
|
|
|
+ "Options" => "B,KB,MB,GB,TB",
|
|
|
+ "Description" => $quotaunitdescription,
|
|
|
+ "Default" => "GB"
|
|
|
+ ),
|
|
|
+ "userwithoutgroup" => array(
|
|
|
+ "FriendlyName" => "User Group",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Description" => "Tick if accounts should be created without nextcloud Group <span></span>"
|
|
|
+ ),
|
|
|
+ "enablegrouplimit" => array(
|
|
|
+ "FriendlyName" => "Group Limit",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Description" => "Tick to Enable Group Limit <span></span> " . $groupLimitHTML . "<tr><td colspan=4 style='font-weight:bold;text-align:center;font-size:13px;'><p class='bg-info' style='padding: 5px;margin: 0px!important;'>Reseller Module Settings</p></td></tr>"
|
|
|
+ ),
|
|
|
+ "customgroup" => array(
|
|
|
+ "FriendlyName" => "Custom Group Name",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Description" => "Tick if you want users can choose group name at their own <span></span>"
|
|
|
+ ),
|
|
|
+ "groupadmin" => array(
|
|
|
+ "FriendlyName" => "Group Admin",
|
|
|
+ "Type" => "yesno",
|
|
|
+ "Description" => "Tick if you want to make user admin of own created groups <span></span>",
|
|
|
+ ),
|
|
|
+ "defaultlimitnewlycreatedgroup" => array(
|
|
|
+ "FriendlyName" => "Default Account Limit",
|
|
|
+ "Type" => "text",
|
|
|
+ "Description" => "Only fill, if <b>Custom Group Name</b> option is ticked"
|
|
|
+ ),
|
|
|
+ */
|
|
|
+ "emailtemplate" => array(
|
|
|
+ "FriendlyName" => "Email Template Name",
|
|
|
+ "Type" => "text",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "Do not leave it empty to resend email",
|
|
|
+ "Default" => "nextcloud Account Welcome Email"
|
|
|
+ ),
|
|
|
+ /*
|
|
|
+ "nextcloudApiAppURL" => array(# nextcloud Api Fields 1
|
|
|
+ "FriendlyName" => "API APP URL",
|
|
|
+ "Type" => "text",
|
|
|
+ "Size" => "35",
|
|
|
+ "Description" => "<a style='text-decoration:none;' href='javacsript::' title='nextcloud API URL(For developer only)'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
|
|
|
+ "Default" => "/ocs/v2.php/apps/",
|
|
|
+ ),
|
|
|
+ */
|
|
|
+ );
|
|
|
+
|
|
|
+ if (Capsule::table('tblemailtemplates')->where('name','nextcloud Account Welcome Email')->count() <= 0) {
|
|
|
+ Capsule::connection()->transaction(
|
|
|
+ function ($connectionManager) {
|
|
|
+ $connectionManager->table('tblemailtemplates')->insert(
|
|
|
+ [
|
|
|
+ 'name' => 'nextcloud Account Welcome Email',
|
|
|
+ 'type' => 'product',
|
|
|
+ 'subject' => 'New nextcloud Account Information',
|
|
|
+ 'message' => '<span>Dear {$client_name},<br /><br />Thank you for your order from us! Your nextcloud account has now been setup and this email contains all the information you will need in order to begin using your account.<br /><br /><strong>New Account Information</strong><br /><br />Domain : {$serverDomain}<br /><br /><strong>Login Details<br /><br /></strong>Username : {$username}<br />Password : {$password}<br /><br /></span><div><span>{$signature}</span></div>',
|
|
|
+ 'custom' => '1',
|
|
|
+ 'plaintext' => '0',
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return $configarray;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_CreateAccount($params) {
|
|
|
+ if (nextcloud_checkLicense_server_file() != 'Active') {
|
|
|
+ return "Your license is " . nextcloud_checkLicense_server_file();
|
|
|
+ }
|
|
|
+
|
|
|
+ $encoding = true; // (empty($params['configoption11'])) ? false : true;
|
|
|
+
|
|
|
+ $action = 'post';
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+ # Password
|
|
|
+ $PASSWORD = substr($params['configoption6'], strpos($params['configoption6'], ':') + 1);
|
|
|
+ $PASSWORD = nextcloud_character_encoding($PASSWORD, $encoding);
|
|
|
+ $cfData = explode('|',$PASSWORD);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $PASSWORD = $cfData[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ # Server Name
|
|
|
+ $servername = $params['configoption7'];
|
|
|
+ $servername = nextcloud_character_encoding($servername, $encoding);
|
|
|
+ # API URL
|
|
|
+ $apiurl = $params['configoption3'];
|
|
|
+ $apiAppurl = $params['configoption21'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+
|
|
|
+ if ($params['serversecure'] == 'on') {
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ } else {
|
|
|
+ $serverSecure = 'http://';
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($params["serverusername"] == "" || $params["serverpassword"] == "" || $params["serverhostname"] == "") {
|
|
|
+ return "Please check your server configuration or Server is not assinged to the module";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (empty($params['configoption10'])) {
|
|
|
+ return 'You did not enter value for Quota';
|
|
|
+ } else {
|
|
|
+ $Quota = trim($params['configoption10']) . " GB";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$params['configoption15']) {
|
|
|
+ if ($params['configoption13']) {
|
|
|
+ if (empty($params['configoption8'])) {
|
|
|
+ return 'You have enabled option "Manage Group", But you did not save value for group';
|
|
|
+ } else {
|
|
|
+ $groupname = trim($params['configoption8']);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $GROUPS = substr($params['configoption8'], strpos($params['configoption8'], ':') + 1);
|
|
|
+ $GROUPS = nextcloud_character_encoding($GROUPS, $encoding);
|
|
|
+ $cfData = explode('|',$GROUPS);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $GROUPS = $cfData[0];
|
|
|
+ }
|
|
|
+ $groupname = $params["customfields"][$GROUPS];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ # Get services using same package
|
|
|
+ $countservicesq = Capsule::select("SELECT COUNT(*) as `services` FROM `tblhosting` WHERE `packageid`=" . $params["packageid"] . " AND `domainstatus`='Active'");
|
|
|
+ $countservicesd = (array) $countservicesq;
|
|
|
+ # Get Account Limit from nextcloud
|
|
|
+ $href1 = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl, $params["configoption2"], "/getgrouplimit/" . $groupname);
|
|
|
+ $response1 = nextcloud_Send($href1, $params["serverusername"], $params["serverpassword"], 'get');
|
|
|
+ $nextcloudGroupLimit = $response1->ocs->data->limit;
|
|
|
+
|
|
|
+ $nextcloudGroupLimit = empty($nextcloudGroupLimit) ? 0 : $nextcloudGroupLimit;
|
|
|
+ # if response is not there
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #Get Users in Group
|
|
|
+ //$href1 = nextcloud_API_URL($serverSecure, $params["serverhostname"], "/ocs/v2.php/apps/", $params["configoption2"], "/usersingroup/" . $groupname);
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'groups/'.$groupname.'/users');
|
|
|
+ $response1 = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], 'get');
|
|
|
+ $usersInGroup = $response1->ocs->data->users;
|
|
|
+ $totalNoOfUsers = count($response1->ocs->data->users);
|
|
|
+ $usersInGroup = empty($usersInGroup) ? array() : $usersInGroup; # if response is not there
|
|
|
+
|
|
|
+
|
|
|
+ if($params['configoption17']){
|
|
|
+ if($totalNoOfUsers >= $params['configoption19']){
|
|
|
+ return "You have set " . $groupname . ' group account limit is ' . $params['configoption19'] . ' in product module setting. You cannot exceed your group account limit.';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($params['configoption16'] && !$params['configoption15']) {
|
|
|
+ $glimitq = Capsule::select("SELECT `accountlimit` FROM `mod_nextcloud_grouplimit` WHERE `productid`=" . $params["packageid"] . " AND `group`='" . $groupname . "'");
|
|
|
+ $glimitd = (array) $glimitq;
|
|
|
+ if ($glimitd["accountlimit"] > 0 && $countservicesd['services'] >= $glimitd["accountlimit"]) { # 0 is for default nextcloud behaviour
|
|
|
+ return $groupname . ' group account limit is ' . $glimitd["accountlimit"] . ' You cannot exceed your group account limit.';
|
|
|
+ } elseif ($glimitd["accountlimit"] == 0 && $nextcloudGroupLimit != 0 && $nextcloudGroupLimit <= count($usersInGroup)) {
|
|
|
+
|
|
|
+ return $groupname . ' group account limit is ' . $glimitd["accountlimit"] . ' You cannot exceed your group account limit.';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ # If group limit is not defined by whmcs, then it will use nextcloud's group limit if defined otherwise to unlimied accounts
|
|
|
+ if (!$params["configoption16"] && !$params['configoption15']) {
|
|
|
+ if ($nextcloudGroupLimit != 0 && $nextcloudGroupLimit < count($usersInGroup)) {
|
|
|
+ return $groupname . ' group account limit is ' . $nextcloudGroupLimit . ' You cannot exceed your group account limit.';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ## Manage user group by admin * Ends
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users');
|
|
|
+ $post = array('userid' => $params["customfields"][$USERNAME], 'password' => $params["customfields"][$PASSWORD]);
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
|
|
|
+
|
|
|
+ # log module call 1
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $response;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "create account => create user", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+
|
|
|
+ if (empty($response)):
|
|
|
+ return 'Please Enable WHMCS Integration APP from your nextcloud installation';
|
|
|
+ endif;
|
|
|
+
|
|
|
+ if ($response->ocs->meta->status == 'failure'): # if nextcloud admin login details are incorrect
|
|
|
+ return 'Please make sure you have entered correct nextcloud admin login details while configuring server or ' . $response->ocs->meta->message;
|
|
|
+ endif;
|
|
|
+
|
|
|
+ if ($response->status == 'failed'):
|
|
|
+ return 'Please make sure module configured successfully';
|
|
|
+ endif;
|
|
|
+
|
|
|
+ if ($response->ocs->meta->status == 'ok'):
|
|
|
+ # Add Email Address to nextcloud Account
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+ $post = array('key' => 'email', 'value' => $params['clientsdetails']['email']);
|
|
|
+ nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "put", $post);
|
|
|
+ #######################################
|
|
|
+ # User without Group
|
|
|
+ if ($params['configoption15']) { # Condition to create user without group
|
|
|
+ $responseg->ocs->meta->status = 'ok';
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME] . '/groups');
|
|
|
+// $post = array('groupid' => $groupname);
|
|
|
+// $responseg = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
|
|
|
+//
|
|
|
+
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl , "whmcsintegration/togglegroups?format=json");
|
|
|
+ $post = array("userid" => $params["customfields"][$USERNAME], "groups" => json_encode(array($groupname)));
|
|
|
+ $responseg = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
|
|
|
+ # log module call 2
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $responseg;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "create account => assign group", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($groupname) || $params['configoption15']): # Condition afer user added to group success
|
|
|
+ //if ($responseg->ocs->meta->status == 'ok'): # Condition afer user added to group success
|
|
|
+ # Make user group admin
|
|
|
+ if ($params['configoption18']) {
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME] . '/subadmins');
|
|
|
+ $post = array('groupid' => $groupname);
|
|
|
+ nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
|
|
|
+ }
|
|
|
+ # #####################
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+ $post = array('key' => 'quota', 'value' => $Quota);
|
|
|
+ $responseq = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "put", $post);
|
|
|
+ if ($responseq->ocs->meta->status == 'ok'):
|
|
|
+ /*
|
|
|
+ *
|
|
|
+ * Clear service username and password
|
|
|
+ *
|
|
|
+ */
|
|
|
+ Capsule::update("update tblhosting set username = '', password='' where id='".$params["serviceid"]."'");
|
|
|
+ /*
|
|
|
+ * Send nextcloud account welcome email to user
|
|
|
+ */
|
|
|
+
|
|
|
+ $command = "sendemail";
|
|
|
+ $adminuser = nextcloud_getAdminId();
|
|
|
+ $values["messagename"] = trim($params['configoption20']);
|
|
|
+ $values["id"] = $params['serviceid'];
|
|
|
+ $values["customvars"] = base64_encode(serialize(array("domain" => $params["serverhostname"], "username" => $params["customfields"][$USERNAME], "password" => $params["customfields"][$PASSWORD])));
|
|
|
+ localAPI($command, $values, $adminuser);
|
|
|
+ $result = 'success';
|
|
|
+ else:
|
|
|
+ $result = "Error occurred while adding quota for user";
|
|
|
+ endif;
|
|
|
+
|
|
|
+ # log module call 3
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $responseq;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "create account => assign quota", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+
|
|
|
+ else:
|
|
|
+ $result = "Error occurred while adding user to group";
|
|
|
+ endif;
|
|
|
+
|
|
|
+ else:
|
|
|
+ $result = "Error occurred while creating a new user";
|
|
|
+ endif;
|
|
|
+
|
|
|
+ return $result;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_TerminateAccount($params) {
|
|
|
+
|
|
|
+ $encoding = (empty($params['configoption11'])) ? false : true;
|
|
|
+
|
|
|
+ $result = Capsule::table('tblhosting')->select('domainstatus')->where('id',$params['serviceid'])->get();
|
|
|
+ $data = (array) $result[0];
|
|
|
+
|
|
|
+ if ('Terminated' == $data['domainstatus']) {
|
|
|
+ return 'Your current status of service is already Terminated';
|
|
|
+ }
|
|
|
+ $action = 'delete';
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+ # API URL
|
|
|
+ $apiurl = $params['configoption3'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+
|
|
|
+
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action);
|
|
|
+
|
|
|
+ if ($response->ocs->meta->status == 'ok') {
|
|
|
+ $result = 'success';
|
|
|
+ } else {
|
|
|
+ $result = 'Your service does not terminated successfully';
|
|
|
+ }
|
|
|
+
|
|
|
+ # log module call
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $response;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "terminate account", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_SuspendAccount($params) {
|
|
|
+
|
|
|
+ $encoding = (empty($params['configoption11'])) ? false : true;
|
|
|
+
|
|
|
+ $result = Capsule::select("select domainstatus from tblhosting where id='".$params['serviceid']."' ");
|
|
|
+ if ('Suspended' == $result[0]->domainstatus) {
|
|
|
+ return 'Your current status of service is already Suspended';
|
|
|
+ }
|
|
|
+
|
|
|
+ $action = 'post';
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($params['serversecure'] == 'on')
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ else
|
|
|
+ $serverSecure = 'http://';
|
|
|
+ # API URL
|
|
|
+ //$apiurl = '/ocs/v2.php/apps/';
|
|
|
+ $apiAppurl = $params['configoption21'];
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl, $params["configoption2"], '/suspenduser');
|
|
|
+
|
|
|
+ $post = array("userid" => $params["customfields"][$USERNAME]);
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
|
|
|
+
|
|
|
+ if ($response->ocs->meta->status == 'ok'):
|
|
|
+ $result = 'success';
|
|
|
+ else:
|
|
|
+ $result = 'Your service does not suspended successfully';
|
|
|
+ endif;
|
|
|
+
|
|
|
+ # log module call
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $response;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "suspend account", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_UnsuspendAccount($params) {
|
|
|
+
|
|
|
+ $encoding = (empty($params['configoption11'])) ? false : true;
|
|
|
+
|
|
|
+ $result = Capsule::select("select domainstatus from tblhosting where id='".$params['serviceid']."' ");
|
|
|
+ if ('Suspended' != $result[0]->domainstatus) {
|
|
|
+ return 'Your current status of service is not suspended, Only suspended service can be unsuspended';
|
|
|
+ }
|
|
|
+
|
|
|
+ $action = 'post';
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+ if ($params['serversecure'] == 'on')
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ else
|
|
|
+ $serverSecure = 'http://';
|
|
|
+ # API URL
|
|
|
+ //$apiurl = '/ocs/v2.php/apps/';
|
|
|
+ $apiAppurl = $params['configoption21'];
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl, $params["configoption2"], '/unsuspenduser');
|
|
|
+ $post = array("userid" => $params["customfields"][$USERNAME]);
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
|
|
|
+ if ($response->ocs->meta->status == 'ok'):
|
|
|
+ $result = 'success';
|
|
|
+ else:
|
|
|
+ $result = 'Your module command failed to unsuspended your service';
|
|
|
+ endif;
|
|
|
+
|
|
|
+ # log module call
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $response;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "unsuspend account", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_ChangePassword($params) {
|
|
|
+
|
|
|
+ if (nextcloud_checkLicense_server_file() != 'Active') {
|
|
|
+ return "Your license is " . nextcloud_checkLicense_server_file();
|
|
|
+ }
|
|
|
+
|
|
|
+ $encoding = (empty($params['configoption11'])) ? false : true;
|
|
|
+
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+ # Password
|
|
|
+ $PASSWORD = substr($params['configoption6'], strpos($params['configoption6'], ':') + 1);
|
|
|
+ $PASSWORD = nextcloud_character_encoding($PASSWORD, $encoding);
|
|
|
+ $PASSWORD02 = $PASSWORD;
|
|
|
+ $cfData = explode('|',$PASSWORD);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $PASSWORD = $cfData[0];
|
|
|
+ }
|
|
|
+ # API URL
|
|
|
+ $apiurl = $params['configoption3'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+
|
|
|
+ if ($params['serversecure'] == 'on')
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ else
|
|
|
+ $serverSecure = 'http://';
|
|
|
+
|
|
|
+ $P = $params["customfields"][$PASSWORD];
|
|
|
+
|
|
|
+ $action = 'put';
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+ $post = array('key' => 'password', 'value' => $params["password"]);
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
|
|
|
+
|
|
|
+ if ($response->ocs->meta->status == 'ok'):
|
|
|
+
|
|
|
+ Capsule::update("UPDATE `tblcustomfieldsvalues` SET value='" . $params["password"] . "' WHERE relid=" . $params["serviceid"] . " && fieldid=(SELECT id FROM `tblcustomfields` WHERE type='product' && relid=" . $params["pid"] . " && fieldname='" . $PASSWORD02 . "' && fieldtype='password')");
|
|
|
+ $result = 'success';
|
|
|
+ else:
|
|
|
+ $result = $response->ocs->meta->message;
|
|
|
+ endif;
|
|
|
+
|
|
|
+ # log module call
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $response;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "change password", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_ChangePackage($params) { # Only upgrade/downgrade quota
|
|
|
+ $encoding = (empty($params['configoption11'])) ? false : true;
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ # Server Name
|
|
|
+ $servername = $params['configoption7'];
|
|
|
+ $servername = nextcloud_character_encoding($servername, $encoding);
|
|
|
+ # API URL
|
|
|
+ $apiurl = $params['configoption3'];
|
|
|
+ $apiAppurl = $params['configoption21'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+
|
|
|
+ if ($params['serversecure'] == 'on')
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ else
|
|
|
+ $serverSecure = 'http://';
|
|
|
+
|
|
|
+ if ($params["serverusername"] == "" || $params["serverpassword"] == "" || $params["serverhostname"] == "") {
|
|
|
+ return "Please check your server configuration or Server is not assinged to the module";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($params['configoption13']) {
|
|
|
+ $groupname = $params['configoption8'];
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl , "whmcsintegration/togglegroups?format=json");
|
|
|
+ $post = array("userid" => $params["customfields"][$USERNAME], "groups" => json_encode(array($groupname)));
|
|
|
+ $responseg = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ($params["configoption12"] == 'on') { # Quota set by admin
|
|
|
+ $Quota = $params["configoption10"] . " " . $params["configoption14"];
|
|
|
+ } else { # Quota set by customer
|
|
|
+ if($params['configoptions']['Quota in GB'] != 0){
|
|
|
+ $QUOTA = substr($params['configoption10'], strpos($params['configoption10'], ':') + 1);
|
|
|
+ $QUOTA = nextcloud_character_encoding($QUOTA, $encoding);
|
|
|
+ $cfData = explode('|',$QUOTA);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $QUOTA = $cfData[0];
|
|
|
+ }
|
|
|
+ $Quota = $params['configoptions'][$QUOTA] . " " . $params['configoption14'];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ $query = Capsule::table('tblproductconfiglinks')->select('gid')->where('pid',$params['pid'])->get();
|
|
|
+ $config_group_id = $query[0]->gid;
|
|
|
+ $query2 = Capsule::table('tblproductconfigoptions')->select('id','qtymaximum')->where('gid',$config_group_id)->get();
|
|
|
+ Capsule::table('tblhostingconfigoptions')->where('relid',$params['serviceid'])->where('configid',$query2[0]->id)->update(['qty' =>$query2[0]->qtymaximum]);;
|
|
|
+ $Quota = $query2[0]->qtymaximum . " " . $params['configoption14'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+ $post = array('key' => 'quota', 'value' => $Quota);
|
|
|
+ //echo "----------------".$params['configoptions']['Quota in GB'];
|
|
|
+ //die();
|
|
|
+ $responseq = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "put", $post);
|
|
|
+ logModuleCall("nextcloud", "change package", $post, (array) $responseq);
|
|
|
+ if ($responseq->ocs->meta->status == 'ok'):
|
|
|
+ return 'success';
|
|
|
+ else:
|
|
|
+ return 'Error occurred while adding quota for user';
|
|
|
+ endif;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_getLang($params) {
|
|
|
+ global $CONFIG;
|
|
|
+ if (!empty($_SESSION['Language']))
|
|
|
+ $language = strtolower($_SESSION['Language']);
|
|
|
+ else if (strtolower($params['clientsdetails']['language']) != '')
|
|
|
+ $language = strtolower($params['clientsdetails']['language']);
|
|
|
+ else
|
|
|
+ $language = $CONFIG['Language'];
|
|
|
+
|
|
|
+ $langfilename = dirname(__FILE__) .'/lang/'. $language . '.php';
|
|
|
+ if (file_exists($langfilename))
|
|
|
+ require_once($langfilename);
|
|
|
+ else
|
|
|
+ require_once(dirname(__FILE__) . '/lang/english.php');
|
|
|
+ if (isset($lang))
|
|
|
+ return $lang;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function nextcloud_ClientArea($params) {
|
|
|
+ if (nextcloud_checkLicense_server_file() != 'Active') {
|
|
|
+ return "Your license is " . nextcloud_checkLicense_server_file();
|
|
|
+ }
|
|
|
+ $langVar = nextcloud_getLang($params);
|
|
|
+ if ($params['serversecure'] == 'on')
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ else
|
|
|
+ $serverSecure = 'http://';
|
|
|
+
|
|
|
+ $encoding = (empty($params['configoption11'])) ? false : true;
|
|
|
+ if(empty($_REQUEST))
|
|
|
+ {
|
|
|
+ $code='';
|
|
|
+ return $code;
|
|
|
+ }
|
|
|
+ # Username
|
|
|
+ $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
|
|
|
+ $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
|
|
|
+ $cfData = explode('|',$USERNAME);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $USERNAME = $cfData[0];
|
|
|
+ }
|
|
|
+ # Password
|
|
|
+ $PASSWORD = substr($params['configoption6'], strpos($params['configoption6'], ':') + 1);
|
|
|
+ $PASSWORD = nextcloud_character_encoding($PASSWORD, $encoding);
|
|
|
+ $cfData = explode('|',$PASSWORD);
|
|
|
+ if(count($cfData)>=2){
|
|
|
+ $PASSWORD = $cfData[0];
|
|
|
+ }
|
|
|
+ # API URL
|
|
|
+ $apiurl = $params['configoption3'];
|
|
|
+ $apiAppurl = $params['configoption21'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+ # Login button value
|
|
|
+ $nextcloudlogin = $params['configoption9'];
|
|
|
+ $nextcloudlogin = nextcloud_character_encoding($nextcloudlogin, $encoding);
|
|
|
+
|
|
|
+ //$autologin = '<form action="' . $serverSecure . $params['serverhostname'] . $apiAppurl.$params["configoption2"].'/autologinuser" method="post" target="_blank" name="login">
|
|
|
+ $autologin = '<form action="' . $serverSecure . $params['serverhostname'].'/index.php/login" method="post" target="_blank" name="login">
|
|
|
+ <input type="hidden" name="username" value="' . $params["customfields"][$USERNAME] . '" />
|
|
|
+ <input type="hidden" name="password" value="' . $params["customfields"][$PASSWORD] . '" />
|
|
|
+ <input type="submit" value="' . $nextcloudlogin . '" class="btn btn-warning modulebutton" />
|
|
|
+ </form>';
|
|
|
+ if (isset($_POST["nextcloud_email"])) {
|
|
|
+ # API URL
|
|
|
+ $appapiurl = $params['configoption21'];
|
|
|
+ if (empty($_POST["nextcloud_email"])) {
|
|
|
+ $action = 'post';
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $appapiurl, $params["configoption2"], '/deluservalue');
|
|
|
+ $post = array('userid' => $params["customfields"][$USERNAME], 'app' => 'settings', 'key' => 'email');
|
|
|
+ $res = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
|
|
|
+ } else {
|
|
|
+ $action = 'put';
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+ $post = array('key' => 'email', 'value' => trim($_POST["nextcloud_email"]));
|
|
|
+ $res = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
|
|
|
+ }
|
|
|
+ # log module call
|
|
|
+ $requeststring = $post;
|
|
|
+ $responsedata = array();
|
|
|
+ $processeddata = (array) $res;
|
|
|
+ $replacevars = array();
|
|
|
+ logModuleCall("nextcloud", "Change Email Address", $requeststring, $responsedata, $processeddata, $replacevars);
|
|
|
+ }
|
|
|
+ $action = 'get';
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action);
|
|
|
+ $email = $response->ocs->data->email;
|
|
|
+ $code = '<form method="post" action="clientarea.php?action=productdetails&id=' . $params["serviceid"] . '"><div class="panel panel-default">
|
|
|
+ <div class="panel-heading">
|
|
|
+ <h3 class="panel-title">'.$langVar['nextcloudSettings'].'</h3>
|
|
|
+ </div>
|
|
|
+ <div class="panel-body text-center">
|
|
|
+ <div class="row">
|
|
|
+ <div class="col-sm-3 col-xs-6"><div class="form-group">'.$langVar['EmailAddress'].'</div></div>
|
|
|
+ <div class="col-sm-6 col-xs-6">
|
|
|
+ <div class="form-group"><input type="text" name="nextcloud_email" value="' . $email . '" class="form-control" placeholder="'.$langVar['nextcloudEmailAddress'].'"></div>
|
|
|
+ </div></div>
|
|
|
+ <div class="row">
|
|
|
+ <div class="col-sm-12 col-xs-12">
|
|
|
+ <div class="form-group"><input type="submit" class="btn btn-primary" value="'.$langVar['ChangenextcloudEmailAddress'].'"></div></div>
|
|
|
+ </div>
|
|
|
+ </div></div></form>';
|
|
|
+
|
|
|
+ $code .= '<div class="row"><div class="col-sm-12 col-xs-12">
|
|
|
+ <div class="form-group">' . $autologin . '</div></div></div>';
|
|
|
+
|
|
|
+ return $code;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_AdminLink($params) {
|
|
|
+ $action = 'get';
|
|
|
+ if ($params['serversecure'] == 'on')
|
|
|
+ $serverSecure = 'https://';
|
|
|
+ else
|
|
|
+ $serverSecure = 'http://';
|
|
|
+
|
|
|
+ # API URL
|
|
|
+ $apiurl = $params['configoption3'];
|
|
|
+ $apiAppurl = $params['configoption21'];
|
|
|
+ //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
|
|
|
+
|
|
|
+ $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, $APP_ID, 'groups');
|
|
|
+ $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action);
|
|
|
+
|
|
|
+ if ($response->status == 'failed'):
|
|
|
+ $value = 'Enable nextcloud APP';
|
|
|
+ else:
|
|
|
+ $value = 'Disable nextcloud APP';
|
|
|
+ endif;
|
|
|
+
|
|
|
+ $code = '<form action="' . $serverSecure . $params["serverhostname"] . '" method="post" target="_blank" name="login">
|
|
|
+ <input type="hidden" name="user" value="' . $params["serverusername"] . '" />
|
|
|
+ <input type="hidden" name="password" value="' . $params["serverpassword"] . '" />
|
|
|
+ <input type="submit" value="' . $value . '" />
|
|
|
+ </form>';
|
|
|
+ return $code;
|
|
|
+}
|
|
|
+
|
|
|
+###########################################################################################################################
|
|
|
+################################################## Custom Functions #######################################################
|
|
|
+###########################################################################################################################
|
|
|
+
|
|
|
+function nextcloud_character_encoding($str, $encoding) {
|
|
|
+
|
|
|
+ $string = ($encoding) ? nextcloud_Encoding::fixUTF8($str) : $str;
|
|
|
+
|
|
|
+ return $string;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_getAdminId() {
|
|
|
+ $Query = Capsule::select("SELECT id FROM `tbladmins` LIMIT 1");
|
|
|
+ $Id = $Query[0]->id;
|
|
|
+ return $Id;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_customfieldsConfigurableOptions($productid) {
|
|
|
+
|
|
|
+ $query = "SELECT concat('CustomField:', fieldname) as ufieldname FROM tblcustomfields WHERE type='product' and relid=" . mysql_real_escape_string($productid) . " UNION SELECT concat('ConfigOption:', optionname) FROM tblproductconfigoptions A, tblproductconfiglinks B WHERE A.gid = B.gid AND B.pid=" . mysql_real_escape_string($productid);
|
|
|
+ $result = Capsule::select($query);
|
|
|
+ $numberOfOptions = 0;
|
|
|
+ $optionsAr = array();
|
|
|
+ foreach($result as $key => $optionValue02) {
|
|
|
+ $optionValue = (array) $optionValue02;
|
|
|
+ $optionsAr[] = $optionValue['ufieldname'];
|
|
|
+ $numberOfOptions++;
|
|
|
+ }
|
|
|
+ $options = implode(",", $optionsAr);
|
|
|
+ return array('result' => 'success', 'availoptions' => $numberOfOptions, 'options' => $options);
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_addCustomfieldsConfigurableFields($productid, $create_configurationoptions, $quotaunits, $enablegroup, $customgroup, $groups) {
|
|
|
+
|
|
|
+ ######################## CREATE CUSTOMFIELDS ######################
|
|
|
+ $customfieldresult = Capsule::table('tblcustomfields')->where('type','product')->where('relid',$productid)->count();
|
|
|
+ $customfields = array(
|
|
|
+ "Username" => "text",
|
|
|
+ "Password" => "password"
|
|
|
+ );
|
|
|
+
|
|
|
+ $addcustomfielddesc = '';
|
|
|
+ $addfieldoptions = '';
|
|
|
+ $addregexpr = '';
|
|
|
+ $addadminonly = '';
|
|
|
+ $addrequired = 'on';
|
|
|
+ $addshoworder = 'on';
|
|
|
+ $addshowinvoice = '';
|
|
|
+ $addsortorder = '';
|
|
|
+ foreach ($customfields as $addfieldname => $addfieldtype) {
|
|
|
+ if ($addfieldtype == "dropdown") {
|
|
|
+ $addfieldoptions = implode(",", $groups);
|
|
|
+ }
|
|
|
+ if ($addfieldtype == "password") {
|
|
|
+ $addcustomfielddesc = "Password must be at least 8 characters, no more than 18 characters.";
|
|
|
+ $addregexpr = "/^.{8,}$/";
|
|
|
+ } else {
|
|
|
+ $addcustomfielddesc = "";
|
|
|
+ $addregexpr = "";
|
|
|
+ }
|
|
|
+ if ($customfieldresult == 0) {
|
|
|
+ Capsule::table('tblcustomfields')->insert(
|
|
|
+ [
|
|
|
+ 'type' => 'product',
|
|
|
+ 'relid' => $productid,
|
|
|
+ 'fieldname' => $addfieldname,
|
|
|
+ 'fieldtype' => $addfieldtype,
|
|
|
+ 'description' => $addcustomfielddesc,
|
|
|
+ 'fieldoptions' => $addfieldoptions,
|
|
|
+ 'regexpr' => html_entity_decode($addregexpr),
|
|
|
+ 'adminonly' => $addadminonly,
|
|
|
+ 'required' => $addrequired,
|
|
|
+ 'showorder' => $addshoworder,
|
|
|
+ 'showinvoice' => $addshowinvoice,
|
|
|
+ 'sortorder' => $addsortorder,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $customfieldcount = Capsule::table("tblcustomfields")->where('type','product')->where('relid',$productid)->where("fieldname",$addfieldname)->count();
|
|
|
+ if($customfieldcount == 0){
|
|
|
+ Capsule::table('tblcustomfields')->insert(
|
|
|
+ [
|
|
|
+ 'type' => 'product',
|
|
|
+ 'relid' => $productid,
|
|
|
+ 'fieldname' => $addfieldname,
|
|
|
+ 'fieldtype' => $addfieldtype,
|
|
|
+ 'description' => $addcustomfielddesc,
|
|
|
+ 'fieldoptions' => $addfieldoptions,
|
|
|
+ 'regexpr' => html_entity_decode($addregexpr),
|
|
|
+ 'adminonly' => $addadminonly,
|
|
|
+ 'required' => $addrequired,
|
|
|
+ 'showorder' => $addshoworder,
|
|
|
+ 'showinvoice' => $addshowinvoice,
|
|
|
+ 'sortorder' => $addsortorder,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ Capsule::table("tblcustomfields")->where('type','product')->where('relid',$productid)->where("fieldname",$addfieldname)->update(
|
|
|
+ [
|
|
|
+ 'type' => 'product',
|
|
|
+ 'relid' => $productid,
|
|
|
+ 'fieldname' => $addfieldname,
|
|
|
+ 'fieldtype' => $addfieldtype,
|
|
|
+ 'description' => $addcustomfielddesc,
|
|
|
+ 'fieldoptions' => $addfieldoptions,
|
|
|
+ 'regexpr' => html_entity_decode($addregexpr),
|
|
|
+ 'adminonly' => $addadminonly,
|
|
|
+ 'required' => $addrequired,
|
|
|
+ 'showorder' => $addshoworder,
|
|
|
+ 'showinvoice' => $addshowinvoice,
|
|
|
+ 'sortorder' => $addsortorder,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($create_configurationoptions) {
|
|
|
+ nextcloud_unlinkproductconfigoptions($productid);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ######################## CONFIGURABLE OPTION #####################
|
|
|
+ $addconfigrablegroupname = "nextcloud Storage" . $productid;
|
|
|
+ $addconfigurabledescription = "Quota in " . $quotaunits;
|
|
|
+ $addconfigurableoptionname = "Quota in " . $quotaunits;
|
|
|
+
|
|
|
+ $configurableoptionresult = Capsule::table('tblproductconfiglinks')->where('pid',$productid)->count();
|
|
|
+ $configurableoptionresultbynameR = Capsule::table('tblproductconfiggroups')->where('name',$addconfigrablegroupname)->count();
|
|
|
+ $configurableoptionresultbyname = Capsule::select("select id from tblproductconfiggroups where name='".$addconfigrablegroupname."'");
|
|
|
+ $configurableoptionresultbynamedata["id"] = $configurableoptionresultbyname[0]->id;
|
|
|
+ if($configurableoptionresultbynameR > 0 && $configurableoptionresult == 0){
|
|
|
+ Capsule::table('tblproductconfiglinks')->insert(
|
|
|
+ [
|
|
|
+ 'gid' => $configurableoptionresultbynamedata["id"],
|
|
|
+ 'pid' => $productid,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ } else if ($configurableoptionresult == 0) {
|
|
|
+
|
|
|
+ $configurablegroupid = Capsule::table('tblproductconfiggroups')->insertGetId(
|
|
|
+ [
|
|
|
+ 'name' => $addconfigrablegroupname,
|
|
|
+ 'description' => $addconfigurabledescription,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ Capsule::table('tblproductconfiglinks')->insertGetId(
|
|
|
+ [
|
|
|
+ 'gid' => $configurablegroupid,
|
|
|
+ 'pid' => $productid,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ $configid = Capsule::table('tblproductconfigoptions')->insertGetId(
|
|
|
+ [
|
|
|
+ 'gid' => $configurablegroupid,
|
|
|
+ 'optionname' => $addconfigurableoptionname,
|
|
|
+ 'optiontype' => '4',
|
|
|
+ 'qtyminimum' => '1',
|
|
|
+ 'qtymaximum' => '10',
|
|
|
+ 'order' => '',
|
|
|
+ 'hidden' => '',
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ $tblpricing_rel_id = Capsule::table('tblproductconfigoptionssub')->insertGetId(
|
|
|
+ [
|
|
|
+ 'configid' => $configid,
|
|
|
+ 'optionname' => '',
|
|
|
+ 'sortorder' => '',
|
|
|
+ 'hidden' => ''
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ $result = Capsule::table('tblcurrencies')->get();
|
|
|
+ foreach($result as $data) {
|
|
|
+ $curr_id = $data->id;
|
|
|
+ $curr_code = $data->code;
|
|
|
+ $currenciesarray[$curr_id] = $curr_code;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($currenciesarray as $curr_id => $currency) {
|
|
|
+ Capsule::table('tblpricing')->insertGetId(
|
|
|
+ [
|
|
|
+ 'type' => 'configoptions',
|
|
|
+ 'currency' => $curr_id,
|
|
|
+ 'relid' => $tblpricing_rel_id,
|
|
|
+ 'msetupfee' => '',
|
|
|
+ 'qsetupfee' => '',
|
|
|
+ 'ssetupfee' => '',
|
|
|
+ 'asetupfee' => '',
|
|
|
+ 'bsetupfee' => '',
|
|
|
+ 'tsetupfee' => '',
|
|
|
+ 'monthly' => '',
|
|
|
+ 'quarterly' => '',
|
|
|
+ 'semiannually' => '',
|
|
|
+ 'annually' => '',
|
|
|
+ 'biennially' => '',
|
|
|
+ 'triennially' => '',
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ###########################################
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_unlinkproductconfigoptions($productid) {
|
|
|
+
|
|
|
+ $addconfigrablegroupname = "nextcloud Storage" . $productid;
|
|
|
+ $chkGroup = Capsule::table('tblproductconfiggroups')->where('name',$addconfigrablegroupname)->count();
|
|
|
+ if($chkGroup!='0') {
|
|
|
+ $query = Capsule::table('tblproductconfiglinks')->select('gid')->where('pid',$productid)->get();
|
|
|
+ $config_group_id = $query[0]->gid;
|
|
|
+
|
|
|
+ $query2 = Capsule::table('tblproductconfigoptions')->select('id')->where('gid',$config_group_id)->get();
|
|
|
+ $config_id = $query2[0]->id;
|
|
|
+
|
|
|
+ $query3 = Capsule::table('tblproductconfigoptionssub')->select('id')->where('configid',$config_id)->get();
|
|
|
+ $pricing_rel_id = $query3[0]->id;
|
|
|
+ if(!empty($pricing_rel_id)){
|
|
|
+ Capsule::table('tblpricing')->where('type','configoptions')->where('relid',$pricing_rel_id)->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($pricing_rel_id)){
|
|
|
+ Capsule::table('tblproductconfigoptionssub')->where('id',$config_id)->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($pricing_rel_id)){
|
|
|
+ Capsule::table('tblproductconfigoptions')->where('gid',$config_group_id)->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($pricing_rel_id)){
|
|
|
+ Capsule::table('tblproductconfiggroups')->where('id',$config_group_id)->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($pricing_rel_id)){
|
|
|
+ Capsule::table('tblproductconfiglinks')->where('gid',$config_group_id)->delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+################################################################################################
|
|
|
+# 19.02.2015
|
|
|
+
|
|
|
+function nextcloud_addGroupCustomField($productid, $fieldname, $create_manageAdminGroup, $userwithoutgroup, $customgroup, $groups) {
|
|
|
+ $group = substr($fieldname, strpos($fieldname, ':') + 1);
|
|
|
+ if ($userwithoutgroup || $create_manageAdminGroup) {
|
|
|
+ //$affectedRow = Capsule::table('tblcustomfields')->where('fieldname',$group)->where('fieldtype','dropdown')->where('type','product')->where('relid',$productid)->delete();
|
|
|
+ $affectedRow = Capsule::delete("delete from tblcustomfields where relid='".$productid."' and type='product' and fieldname like 'Group%' ");
|
|
|
+// if ($affectedRow == 0) {
|
|
|
+// Capsule::table('tblcustomfields')->where('type','product')->where('relid',$productid)->delete();
|
|
|
+// }
|
|
|
+ } elseif ((!$create_manageAdminGroup && !$userwithoutgroup) && !$customgroup) {
|
|
|
+// if (!strpos($fieldname, ":")) {
|
|
|
+ $avail_group_result = Capsule::select("SELECT count(*) as `group_field` FROM `tblcustomfields` WHERE `fieldtype`='dropdown' AND `type`='product' AND `relid`=" . $productid);
|
|
|
+ $avail_group_data = (array) $avail_group_result[0];
|
|
|
+
|
|
|
+ if ($avail_group_data['group_field'] == 0) {
|
|
|
+ $addfieldname = "Group";
|
|
|
+ $addfieldtype = "dropdown";
|
|
|
+ $addcustomfielddesc = '';
|
|
|
+ $addfieldoptions = implode(",", $groups);
|
|
|
+ $addregexpr = '';
|
|
|
+ $addadminonly = '';
|
|
|
+ $addrequired = 'on';
|
|
|
+ $addshoworder = 'on';
|
|
|
+ $addshowinvoice = '';
|
|
|
+ $addsortorder = '';
|
|
|
+
|
|
|
+ Capsule::table('tblcustomfields')->insertGetId(
|
|
|
+ [
|
|
|
+ 'type' => 'product',
|
|
|
+ 'relid' => $productid,
|
|
|
+ 'fieldname' => $addfieldname,
|
|
|
+ 'fieldtype' => $addfieldtype,
|
|
|
+ 'description' => $addcustomfielddesc,
|
|
|
+ 'fieldoptions' => $addfieldoptions,
|
|
|
+ 'regexpr' => html_entity_decode($addregexpr),
|
|
|
+ 'adminonly' => $addadminonly,
|
|
|
+ 'required' => $addrequired,
|
|
|
+ 'showorder' => $addshoworder,
|
|
|
+ 'showinvoice' => $addshowinvoice,
|
|
|
+ 'sortorder' => $addsortorder,
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+// }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_remove_utf8bom($text) {
|
|
|
+ $bom = pack('H*', 'EFBBBF');
|
|
|
+ $text = preg_replace("/^$bom/", '', $text);
|
|
|
+ return $text;
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_Send($href, $username, $password, $action, $post = array()) {
|
|
|
+ $postdata = http_build_query($post);
|
|
|
+ $ch = curl_init();
|
|
|
+ if (strtoupper($action) == 'POST'):
|
|
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
+ if ($postdata)
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
|
|
|
+ endif;
|
|
|
+
|
|
|
+ if (strtoupper($action) == 'PUT'):
|
|
|
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
|
|
+ if ($postdata)
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
|
|
|
+ endif;
|
|
|
+
|
|
|
+ if (strtoupper($action) == 'GET'):
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPGET, true);
|
|
|
+ endif;
|
|
|
+
|
|
|
+ if (strtoupper($action) == 'DELETE'):
|
|
|
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
|
|
+ endif;
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $href);
|
|
|
+ curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
|
|
+ $result_json = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ //print_r($result_json);die();
|
|
|
+ $result_bom = nextcloud_remove_utf8bom($result_json);
|
|
|
+ $result = json_decode($result_bom);
|
|
|
+
|
|
|
+ return($result);
|
|
|
+}
|
|
|
+
|
|
|
+function nextcloud_API_URL($serverSecure, $host, $apiurl, $app_id = NULL, $action = '') {
|
|
|
+ $url = $serverSecure . $host . $apiurl . $app_id . $action . '?format=json';
|
|
|
+ return $url;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+######################################## Encoding Class ######################################33
|
|
|
+
|
|
|
+class nextcloud_Encoding {
|
|
|
+
|
|
|
+ const ICONV_TRANSLIT = "TRANSLIT";
|
|
|
+ const ICONV_IGNORE = "IGNORE";
|
|
|
+ const WITHOUT_ICONV = "";
|
|
|
+
|
|
|
+ protected static $win1252ToUtf8 = array(
|
|
|
+ 128 => "\xe2\x82\xac",
|
|
|
+ 130 => "\xe2\x80\x9a",
|
|
|
+ 131 => "\xc6\x92",
|
|
|
+ 132 => "\xe2\x80\x9e",
|
|
|
+ 133 => "\xe2\x80\xa6",
|
|
|
+ 134 => "\xe2\x80\xa0",
|
|
|
+ 135 => "\xe2\x80\xa1",
|
|
|
+ 136 => "\xcb\x86",
|
|
|
+ 137 => "\xe2\x80\xb0",
|
|
|
+ 138 => "\xc5\xa0",
|
|
|
+ 139 => "\xe2\x80\xb9",
|
|
|
+ 140 => "\xc5\x92",
|
|
|
+ 142 => "\xc5\xbd",
|
|
|
+ 145 => "\xe2\x80\x98",
|
|
|
+ 146 => "\xe2\x80\x99",
|
|
|
+ 147 => "\xe2\x80\x9c",
|
|
|
+ 148 => "\xe2\x80\x9d",
|
|
|
+ 149 => "\xe2\x80\xa2",
|
|
|
+ 150 => "\xe2\x80\x93",
|
|
|
+ 151 => "\xe2\x80\x94",
|
|
|
+ 152 => "\xcb\x9c",
|
|
|
+ 153 => "\xe2\x84\xa2",
|
|
|
+ 154 => "\xc5\xa1",
|
|
|
+ 155 => "\xe2\x80\xba",
|
|
|
+ 156 => "\xc5\x93",
|
|
|
+ 158 => "\xc5\xbe",
|
|
|
+ 159 => "\xc5\xb8"
|
|
|
+ );
|
|
|
+ protected static $brokenUtf8ToUtf8 = array(
|
|
|
+ "\xc2\x80" => "\xe2\x82\xac",
|
|
|
+ "\xc2\x82" => "\xe2\x80\x9a",
|
|
|
+ "\xc2\x83" => "\xc6\x92",
|
|
|
+ "\xc2\x84" => "\xe2\x80\x9e",
|
|
|
+ "\xc2\x85" => "\xe2\x80\xa6",
|
|
|
+ "\xc2\x86" => "\xe2\x80\xa0",
|
|
|
+ "\xc2\x87" => "\xe2\x80\xa1",
|
|
|
+ "\xc2\x88" => "\xcb\x86",
|
|
|
+ "\xc2\x89" => "\xe2\x80\xb0",
|
|
|
+ "\xc2\x8a" => "\xc5\xa0",
|
|
|
+ "\xc2\x8b" => "\xe2\x80\xb9",
|
|
|
+ "\xc2\x8c" => "\xc5\x92",
|
|
|
+ "\xc2\x8e" => "\xc5\xbd",
|
|
|
+ "\xc2\x91" => "\xe2\x80\x98",
|
|
|
+ "\xc2\x92" => "\xe2\x80\x99",
|
|
|
+ "\xc2\x93" => "\xe2\x80\x9c",
|
|
|
+ "\xc2\x94" => "\xe2\x80\x9d",
|
|
|
+ "\xc2\x95" => "\xe2\x80\xa2",
|
|
|
+ "\xc2\x96" => "\xe2\x80\x93",
|
|
|
+ "\xc2\x97" => "\xe2\x80\x94",
|
|
|
+ "\xc2\x98" => "\xcb\x9c",
|
|
|
+ "\xc2\x99" => "\xe2\x84\xa2",
|
|
|
+ "\xc2\x9a" => "\xc5\xa1",
|
|
|
+ "\xc2\x9b" => "\xe2\x80\xba",
|
|
|
+ "\xc2\x9c" => "\xc5\x93",
|
|
|
+ "\xc2\x9e" => "\xc5\xbe",
|
|
|
+ "\xc2\x9f" => "\xc5\xb8"
|
|
|
+ );
|
|
|
+ protected static $utf8ToWin1252 = array(
|
|
|
+ "\xe2\x82\xac" => "\x80",
|
|
|
+ "\xe2\x80\x9a" => "\x82",
|
|
|
+ "\xc6\x92" => "\x83",
|
|
|
+ "\xe2\x80\x9e" => "\x84",
|
|
|
+ "\xe2\x80\xa6" => "\x85",
|
|
|
+ "\xe2\x80\xa0" => "\x86",
|
|
|
+ "\xe2\x80\xa1" => "\x87",
|
|
|
+ "\xcb\x86" => "\x88",
|
|
|
+ "\xe2\x80\xb0" => "\x89",
|
|
|
+ "\xc5\xa0" => "\x8a",
|
|
|
+ "\xe2\x80\xb9" => "\x8b",
|
|
|
+ "\xc5\x92" => "\x8c",
|
|
|
+ "\xc5\xbd" => "\x8e",
|
|
|
+ "\xe2\x80\x98" => "\x91",
|
|
|
+ "\xe2\x80\x99" => "\x92",
|
|
|
+ "\xe2\x80\x9c" => "\x93",
|
|
|
+ "\xe2\x80\x9d" => "\x94",
|
|
|
+ "\xe2\x80\xa2" => "\x95",
|
|
|
+ "\xe2\x80\x93" => "\x96",
|
|
|
+ "\xe2\x80\x94" => "\x97",
|
|
|
+ "\xcb\x9c" => "\x98",
|
|
|
+ "\xe2\x84\xa2" => "\x99",
|
|
|
+ "\xc5\xa1" => "\x9a",
|
|
|
+ "\xe2\x80\xba" => "\x9b",
|
|
|
+ "\xc5\x93" => "\x9c",
|
|
|
+ "\xc5\xbe" => "\x9e",
|
|
|
+ "\xc5\xb8" => "\x9f"
|
|
|
+ );
|
|
|
+
|
|
|
+ static function toUTF8($text) {
|
|
|
+
|
|
|
+ if (is_array($text)) {
|
|
|
+ foreach ($text as $k => $v) {
|
|
|
+ $text[$k] = self::toUTF8($v);
|
|
|
+ }
|
|
|
+ return $text;
|
|
|
+ } elseif (is_string($text)) {
|
|
|
+
|
|
|
+ if (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
|
|
+ $max = mb_strlen($text, '8bit');
|
|
|
+ } else {
|
|
|
+ $max = strlen($text);
|
|
|
+ }
|
|
|
+
|
|
|
+ $buf = "";
|
|
|
+ for ($i = 0; $i < $max; $i++) {
|
|
|
+ $c1 = $text{$i};
|
|
|
+ if ($c1 >= "\xc0") { //Should be converted to UTF8, if it's not UTF8 already
|
|
|
+ $c2 = $i + 1 >= $max ? "\x00" : $text{$i + 1};
|
|
|
+ $c3 = $i + 2 >= $max ? "\x00" : $text{$i + 2};
|
|
|
+ $c4 = $i + 3 >= $max ? "\x00" : $text{$i + 3};
|
|
|
+ if ($c1 >= "\xc0" & $c1 <= "\xdf") { //looks like 2 bytes UTF8
|
|
|
+ if ($c2 >= "\x80" && $c2 <= "\xbf") { //yeah, almost sure it's UTF8 already
|
|
|
+ $buf .= $c1 . $c2;
|
|
|
+ $i++;
|
|
|
+ } else { //not valid UTF8. Convert it.
|
|
|
+ $cc1 = (chr(ord($c1) / 64) | "\xc0");
|
|
|
+ $cc2 = ($c1 & "\x3f") | "\x80";
|
|
|
+ $buf .= $cc1 . $cc2;
|
|
|
+ }
|
|
|
+ } elseif ($c1 >= "\xe0" & $c1 <= "\xef") { //looks like 3 bytes UTF8
|
|
|
+ if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { //yeah, almost sure it's UTF8 already
|
|
|
+ $buf .= $c1 . $c2 . $c3;
|
|
|
+ $i = $i + 2;
|
|
|
+ } else { //not valid UTF8. Convert it.
|
|
|
+ $cc1 = (chr(ord($c1) / 64) | "\xc0");
|
|
|
+ $cc2 = ($c1 & "\x3f") | "\x80";
|
|
|
+ $buf .= $cc1 . $cc2;
|
|
|
+ }
|
|
|
+ } elseif ($c1 >= "\xf0" & $c1 <= "\xf7") { //looks like 4 bytes UTF8
|
|
|
+ if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { //yeah, almost sure it's UTF8 already
|
|
|
+ $buf .= $c1 . $c2 . $c3 . $c4;
|
|
|
+ $i = $i + 3;
|
|
|
+ } else { //not valid UTF8. Convert it.
|
|
|
+ $cc1 = (chr(ord($c1) / 64) | "\xc0");
|
|
|
+ $cc2 = ($c1 & "\x3f") | "\x80";
|
|
|
+ $buf .= $cc1 . $cc2;
|
|
|
+ }
|
|
|
+ } else { //doesn't look like UTF8, but should be converted
|
|
|
+ $cc1 = (chr(ord($c1) / 64) | "\xc0");
|
|
|
+ $cc2 = (($c1 & "\x3f") | "\x80");
|
|
|
+ $buf .= $cc1 . $cc2;
|
|
|
+ }
|
|
|
+ } elseif (($c1 & "\xc0") == "\x80") { // needs conversion
|
|
|
+ if (isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
|
|
|
+ $buf .= self::$win1252ToUtf8[ord($c1)];
|
|
|
+ } else {
|
|
|
+ $cc1 = (chr(ord($c1) / 64) | "\xc0");
|
|
|
+ $cc2 = (($c1 & "\x3f") | "\x80");
|
|
|
+ $buf .= $cc1 . $cc2;
|
|
|
+ }
|
|
|
+ } else { // it doesn't need conversion
|
|
|
+ $buf .= $c1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $buf;
|
|
|
+ } else {
|
|
|
+ return $text;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static function toWin1252($text, $option = self::WITHOUT_ICONV) {
|
|
|
+ if (is_array($text)) {
|
|
|
+ foreach ($text as $k => $v) {
|
|
|
+ $text[$k] = self::toWin1252($v, $option);
|
|
|
+ }
|
|
|
+ return $text;
|
|
|
+ } elseif (is_string($text)) {
|
|
|
+ return static::utf8_decode($text, $option);
|
|
|
+ } else {
|
|
|
+ return $text;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static function toISO8859($text) {
|
|
|
+ return self::toWin1252($text);
|
|
|
+ }
|
|
|
+
|
|
|
+ static function toLatin1($text) {
|
|
|
+ return self::toWin1252($text);
|
|
|
+ }
|
|
|
+
|
|
|
+ static function fixUTF8($text, $option = self::WITHOUT_ICONV) {
|
|
|
+ if (is_array($text)) {
|
|
|
+ foreach ($text as $k => $v) {
|
|
|
+ $text[$k] = self::fixUTF8($v, $option);
|
|
|
+ }
|
|
|
+ return $text;
|
|
|
+ }
|
|
|
+
|
|
|
+ $last = "";
|
|
|
+ while ($last <> $text) {
|
|
|
+ $last = $text;
|
|
|
+ $text = self::toUTF8(static::utf8_decode($text, $option));
|
|
|
+ }
|
|
|
+ $text = self::toUTF8(static::utf8_decode($text, $option));
|
|
|
+ return $text;
|
|
|
+ }
|
|
|
+
|
|
|
+ static function UTF8FixWin1252Chars($text) {
|
|
|
+ // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1
|
|
|
+ // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it.
|
|
|
+ // See: http://en.wikipedia.org/wiki/Windows-1252
|
|
|
+
|
|
|
+ return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text);
|
|
|
+ }
|
|
|
+
|
|
|
+ static function removeBOM($str = "") {
|
|
|
+ if (substr($str, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
|
|
|
+ $str = substr($str, 3);
|
|
|
+ }
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function normalizeEncoding($encodingLabel) {
|
|
|
+ $encoding = strtoupper($encodingLabel);
|
|
|
+ $encoding = preg_replace('/[^a-zA-Z0-9\s]/', '', $encoding);
|
|
|
+ $equivalences = array(
|
|
|
+ 'ISO88591' => 'ISO-8859-1',
|
|
|
+ 'ISO8859' => 'ISO-8859-1',
|
|
|
+ 'ISO' => 'ISO-8859-1',
|
|
|
+ 'LATIN1' => 'ISO-8859-1',
|
|
|
+ 'LATIN' => 'ISO-8859-1',
|
|
|
+ 'UTF8' => 'UTF-8',
|
|
|
+ 'UTF' => 'UTF-8',
|
|
|
+ 'WIN1252' => 'ISO-8859-1',
|
|
|
+ 'WINDOWS1252' => 'ISO-8859-1'
|
|
|
+ );
|
|
|
+
|
|
|
+ if (empty($equivalences[$encoding])) {
|
|
|
+ return 'UTF-8';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $equivalences[$encoding];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function encode($encodingLabel, $text) {
|
|
|
+ $encodingLabel = self::normalizeEncoding($encodingLabel);
|
|
|
+ if ($encodingLabel == 'UTF-8')
|
|
|
+ return Encoding::toUTF8($text);
|
|
|
+ if ($encodingLabel == 'ISO-8859-1')
|
|
|
+ return Encoding::toLatin1($text);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected static function utf8_decode($text, $option) {
|
|
|
+ if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) {
|
|
|
+ $o = utf8_decode(
|
|
|
+ str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $o = iconv("UTF-8", "Windows-1252" . ($option == self::ICONV_TRANSLIT ? '//TRANSLIT' : ($option == self::ICONV_IGNORE ? '//IGNORE' : '')), $text);
|
|
|
+ }
|
|
|
+ return $o;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+?>
|