nextcloud.php.old 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  1. <?php
  2. use Illuminate\Database\Capsule\Manager as Capsule;
  3. if (!defined("WHMCS")) {
  4. die("This file cannot be accessed directly");
  5. }
  6. function nextcloud_ConfigOptions() {
  7. global $whmcs;
  8. $productid = (int) $_REQUEST['id'];
  9. foreach(Capsule::table('tbladdonmodules')->where('module', 'nextcloud')->whereIn('setting', array('licensekey','nextcloudLicenseStatus'))->get() as $dataLicenseKey){
  10. $stValue = $dataLicenseKey->setting;
  11. $$stValue = $dataLicenseKey->value;
  12. }
  13. $updatedUserCount = Capsule::table('tblproducts')->where('id', $productid)->update(['configoption1' => $licensekey,]);
  14. $configValues = Capsule::table('tblproducts')->where('id', $productid)->get();
  15. $configValues = (array) $configValues[0];
  16. /*
  17. * Fetch nextcloud Groups* Starts
  18. */
  19. $nextcloudLicenseStatus = 'Active';
  20. $servername = $configValues['configoption7'];
  21. $serverDetailsQuery = Capsule::table('tblservers')->where('name', $servername)->where('type', 'nextcloud')->get();
  22. $serverDetails = (array) $serverDetailsQuery[0];
  23. $apiurl = $configValues['configoption3'];
  24. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  25. if ($serverDetails['secure'] == 'on') {
  26. $serverSecure = 'https://';
  27. } else {
  28. $serverSecure = 'http://';
  29. $decryptedpassword = html_entity_decode(decrypt($serverDetails['password']));
  30. $href = nextcloud_API_URL($serverSecure, $serverDetails["hostname"], $apiurl, $configValues["configoption5"]);
  31. $response = nextcloud_Send($href, $serverDetails["username"], $decryptedpassword, 'get');
  32. }
  33. $groups = array();
  34. if ($response->ocs->meta->status == 'ok') {
  35. foreach ($response->ocs->data->groups as $key => $value):
  36. $groups[] = $value;
  37. endforeach;
  38. unset($groups[array_search("admin", $groups)]);
  39. }
  40. /*
  41. *
  42. * Fetch nextcloud Groups* Ends
  43. *
  44. */
  45. $create_configurationoptions = empty($configValues['configoption12']) ? false : true;
  46. //nextcloud_addCustomfieldsConfigurableFields($productid, $create_configurationoptions, $configValues['configoption14'], $configValues['configoption15'], $configValues['configoption17'], $groups);
  47. nextcloud_addCustomfieldsConfigurableFields($productid, true, "GB", false, $configValues['configoption17'], $groups);
  48. $optionsresult = nextcloud_customfieldsConfigurableOptions($productid);
  49. if ($optionsresult['result'] == 'success') {
  50. if ($optionsresult['availoptions'] == 0)
  51. $options = '-- No options --';
  52. else
  53. $options = $optionsresult['options'];
  54. }
  55. $quotaunitdescription = "";
  56. if (!is_numeric($configValues['configoption10']) && !empty($configValues['configoption10'])) {
  57. Capsule::table('tblproducts')->where('id', $productid)->update(['configoption10' => '']);
  58. $redirect = true;
  59. }
  60. $quotaType = "text";
  61. $quotaFriendlyName = "Quota in GB ";
  62. $quotaOptions = "";
  63. $quotaDescription = "Please enter value for Quota in Gigabytes";
  64. $configarray = array(
  65. /*
  66. "nextcloudApiURL" => array(# nextcloud Api Fields 1
  67. "FriendlyName" => "API URL",
  68. "Type" => "text",
  69. "Size" => "35",
  70. "Description" => "<a style='text-decoration:none;' href='javacsript::' title='nextcloud API URL(For developer only)'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
  71. "Default" => "/ocs/v2.php/cloud/",
  72. ),
  73. */
  74. /*
  75. "fetchGroups" => array(# nextcloud Api Fields 2
  76. "FriendlyName" => "Group API",
  77. "Type" => "text",
  78. "Size" => "35",
  79. "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>",
  80. "Default" => "/groups",
  81. ),
  82. */
  83. "serverName" => array(# nextcloud Api Fields 3
  84. "FriendlyName" => "Server Name",
  85. "Type" => "text",
  86. "Size" => "35",
  87. "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>",
  88. #"Default" => "Example",
  89. ),
  90. "autonextcloudLogin" => array(# nextcloud Api Fields 4
  91. "FriendlyName" => "Login Button",
  92. "Type" => "text",
  93. "Size" => "35",
  94. "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>",
  95. #"Default" => "Example",
  96. ),
  97. "nextcloudUsername" => array(# Clientarea Fields 1
  98. "FriendlyName" => "Username",
  99. "Type" => "dropdown",
  100. "Size" => "35",
  101. "Options" => $options,
  102. "Description" => "<a style='text-decoration:none;' href='javacsript::' title='Customfield for nextcloud account username'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
  103. #"Default" => "Example",
  104. ),
  105. "nextcloudQuota" => array(# Clientarea Fields 4
  106. "FriendlyName" => $quotaFriendlyName,
  107. "Type" => $quotaType,
  108. "Size" => "28",
  109. "Options" => $quotaOptions,
  110. "Description" => "<a style='text-decoration:none;' href='javacsript::' title='$quotaDescription'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
  111. //"Default" => $quotaDefault,
  112. ),
  113. "nextcloudPassword" => array(# Clientarea Fields 2
  114. "FriendlyName" => "Password",
  115. "Type" => "dropdown",
  116. "Size" => "35",
  117. "Options" => $options,
  118. "Description" => "<a style='text-decoration:none;' href='javacsript::' title='Customfield for nextcloud account password'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
  119. #"Default" => "Example",
  120. ),
  121. /*
  122. "nextcloudGroup" => array(# Clientarea Fields 3
  123. "FriendlyName" => $groupFriendlyName,
  124. "Type" => $groupType,
  125. "Size" => "35",
  126. "Options" => $groupOptions,
  127. "Description" => "<a style='text-decoration:none;' href='javacsript::' title='" . $groupDescription . "'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
  128. #"Default" => "Example",
  129. ),
  130. */
  131. /*
  132. "cloudEncoding" => array(# nextcloud Character Settings Field
  133. "FriendlyName" => "Encoding",
  134. "Type" => "yesno",
  135. "Size" => "35",
  136. "Description" => "Character Encoding",
  137. "Default" => "Example",
  138. ),
  139. "quotaManageAdmin" => array(# nextcloud Quota Settings Field
  140. "FriendlyName" => "Manage Quota",
  141. "Type" => "yesno",
  142. "Size" => "35",
  143. "Description" => "Allow admin to manage Quota <span></span>",
  144. #"Default" => "Example",
  145. ),
  146. "groupManageAdmin" => array(# nextcloud Quota Settings Field
  147. "FriendlyName" => "Manage Group",
  148. "Type" => "yesno",
  149. "Size" => "35",
  150. "Description" => "Allow admin to manage user group <span></span>",
  151. #"Default" => "Example",
  152. ),
  153. "quotaunits" => array(
  154. "FriendlyName" => "Quota Units",
  155. "Type" => "dropdown",
  156. "Options" => "B,KB,MB,GB,TB",
  157. "Description" => $quotaunitdescription,
  158. "Default" => "GB"
  159. ),
  160. "userwithoutgroup" => array(
  161. "FriendlyName" => "User Group",
  162. "Type" => "yesno",
  163. "Description" => "Tick if accounts should be created without nextcloud Group <span></span>"
  164. ),
  165. "enablegrouplimit" => array(
  166. "FriendlyName" => "Group Limit",
  167. "Type" => "yesno",
  168. "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>"
  169. ),
  170. "customgroup" => array(
  171. "FriendlyName" => "Custom Group Name",
  172. "Type" => "yesno",
  173. "Description" => "Tick if you want users can choose group name at their own <span></span>"
  174. ),
  175. "groupadmin" => array(
  176. "FriendlyName" => "Group Admin",
  177. "Type" => "yesno",
  178. "Description" => "Tick if you want to make user admin of own created groups <span></span>",
  179. ),
  180. "defaultlimitnewlycreatedgroup" => array(
  181. "FriendlyName" => "Default Account Limit",
  182. "Type" => "text",
  183. "Description" => "Only fill, if <b>Custom Group Name</b> option is ticked"
  184. ),
  185. */
  186. "emailtemplate" => array(
  187. "FriendlyName" => "Email Template Name",
  188. "Type" => "text",
  189. "Size" => "35",
  190. "Description" => "Do not leave it empty to resend email",
  191. "Default" => "nextcloud Account Welcome Email"
  192. ),
  193. /*
  194. "nextcloudApiAppURL" => array(# nextcloud Api Fields 1
  195. "FriendlyName" => "API APP URL",
  196. "Type" => "text",
  197. "Size" => "35",
  198. "Description" => "<a style='text-decoration:none;' href='javacsript::' title='nextcloud API URL(For developer only)'><img src='../modules/addons/nextcloud/images/info.gif'></a>",
  199. "Default" => "/ocs/v2.php/apps/",
  200. ),
  201. */
  202. );
  203. if (Capsule::table('tblemailtemplates')->where('name','nextcloud Account Welcome Email')->count() <= 0) {
  204. Capsule::connection()->transaction(
  205. function ($connectionManager) {
  206. $connectionManager->table('tblemailtemplates')->insert(
  207. [
  208. 'name' => 'nextcloud Account Welcome Email',
  209. 'type' => 'product',
  210. 'subject' => 'New nextcloud Account Information',
  211. '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>',
  212. 'custom' => '1',
  213. 'plaintext' => '0',
  214. ]
  215. );
  216. }
  217. );
  218. }
  219. return $configarray;
  220. }
  221. function nextcloud_CreateAccount($params) {
  222. if (nextcloud_checkLicense_server_file() != 'Active') {
  223. return "Your license is " . nextcloud_checkLicense_server_file();
  224. }
  225. $encoding = true; // (empty($params['configoption11'])) ? false : true;
  226. $action = 'post';
  227. # Username
  228. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  229. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  230. $cfData = explode('|',$USERNAME);
  231. if(count($cfData)>=2){
  232. $USERNAME = $cfData[0];
  233. }
  234. # Password
  235. $PASSWORD = substr($params['configoption6'], strpos($params['configoption6'], ':') + 1);
  236. $PASSWORD = nextcloud_character_encoding($PASSWORD, $encoding);
  237. $cfData = explode('|',$PASSWORD);
  238. if(count($cfData)>=2){
  239. $PASSWORD = $cfData[0];
  240. }
  241. # Server Name
  242. $servername = $params['configoption7'];
  243. $servername = nextcloud_character_encoding($servername, $encoding);
  244. # API URL
  245. $apiurl = $params['configoption3'];
  246. $apiAppurl = $params['configoption21'];
  247. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  248. if ($params['serversecure'] == 'on') {
  249. $serverSecure = 'https://';
  250. } else {
  251. $serverSecure = 'http://';
  252. }
  253. if ($params["serverusername"] == "" || $params["serverpassword"] == "" || $params["serverhostname"] == "") {
  254. return "Please check your server configuration or Server is not assinged to the module";
  255. }
  256. if (empty($params['configoption10'])) {
  257. return 'You did not enter value for Quota';
  258. } else {
  259. $Quota = trim($params['configoption10']) . " GB";
  260. }
  261. if (!$params['configoption15']) {
  262. if ($params['configoption13']) {
  263. if (empty($params['configoption8'])) {
  264. return 'You have enabled option "Manage Group", But you did not save value for group';
  265. } else {
  266. $groupname = trim($params['configoption8']);
  267. }
  268. } else {
  269. $GROUPS = substr($params['configoption8'], strpos($params['configoption8'], ':') + 1);
  270. $GROUPS = nextcloud_character_encoding($GROUPS, $encoding);
  271. $cfData = explode('|',$GROUPS);
  272. if(count($cfData)>=2){
  273. $GROUPS = $cfData[0];
  274. }
  275. $groupname = $params["customfields"][$GROUPS];
  276. }
  277. }
  278. # Get services using same package
  279. $countservicesq = Capsule::select("SELECT COUNT(*) as `services` FROM `tblhosting` WHERE `packageid`=" . $params["packageid"] . " AND `domainstatus`='Active'");
  280. $countservicesd = (array) $countservicesq;
  281. # Get Account Limit from nextcloud
  282. $href1 = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl, $params["configoption2"], "/getgrouplimit/" . $groupname);
  283. $response1 = nextcloud_Send($href1, $params["serverusername"], $params["serverpassword"], 'get');
  284. $nextcloudGroupLimit = $response1->ocs->data->limit;
  285. $nextcloudGroupLimit = empty($nextcloudGroupLimit) ? 0 : $nextcloudGroupLimit;
  286. # if response is not there
  287. #Get Users in Group
  288. //$href1 = nextcloud_API_URL($serverSecure, $params["serverhostname"], "/ocs/v2.php/apps/", $params["configoption2"], "/usersingroup/" . $groupname);
  289. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'groups/'.$groupname.'/users');
  290. $response1 = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], 'get');
  291. $usersInGroup = $response1->ocs->data->users;
  292. $totalNoOfUsers = count($response1->ocs->data->users);
  293. $usersInGroup = empty($usersInGroup) ? array() : $usersInGroup; # if response is not there
  294. if($params['configoption17']){
  295. if($totalNoOfUsers >= $params['configoption19']){
  296. return "You have set " . $groupname . ' group account limit is ' . $params['configoption19'] . ' in product module setting. You cannot exceed your group account limit.';
  297. }
  298. }
  299. if ($params['configoption16'] && !$params['configoption15']) {
  300. $glimitq = Capsule::select("SELECT `accountlimit` FROM `mod_nextcloud_grouplimit` WHERE `productid`=" . $params["packageid"] . " AND `group`='" . $groupname . "'");
  301. $glimitd = (array) $glimitq;
  302. if ($glimitd["accountlimit"] > 0 && $countservicesd['services'] >= $glimitd["accountlimit"]) { # 0 is for default nextcloud behaviour
  303. return $groupname . ' group account limit is ' . $glimitd["accountlimit"] . ' You cannot exceed your group account limit.';
  304. } elseif ($glimitd["accountlimit"] == 0 && $nextcloudGroupLimit != 0 && $nextcloudGroupLimit <= count($usersInGroup)) {
  305. return $groupname . ' group account limit is ' . $glimitd["accountlimit"] . ' You cannot exceed your group account limit.';
  306. }
  307. }
  308. # If group limit is not defined by whmcs, then it will use nextcloud's group limit if defined otherwise to unlimied accounts
  309. if (!$params["configoption16"] && !$params['configoption15']) {
  310. if ($nextcloudGroupLimit != 0 && $nextcloudGroupLimit < count($usersInGroup)) {
  311. return $groupname . ' group account limit is ' . $nextcloudGroupLimit . ' You cannot exceed your group account limit.';
  312. }
  313. }
  314. ## Manage user group by admin * Ends
  315. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users');
  316. $post = array('userid' => $params["customfields"][$USERNAME], 'password' => $params["customfields"][$PASSWORD]);
  317. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
  318. # log module call 1
  319. $requeststring = $post;
  320. $responsedata = array();
  321. $processeddata = (array) $response;
  322. $replacevars = array();
  323. logModuleCall("nextcloud", "create account => create user", $requeststring, $responsedata, $processeddata, $replacevars);
  324. if (empty($response)):
  325. return 'Please Enable WHMCS Integration APP from your nextcloud installation';
  326. endif;
  327. if ($response->ocs->meta->status == 'failure'): # if nextcloud admin login details are incorrect
  328. return 'Please make sure you have entered correct nextcloud admin login details while configuring server or ' . $response->ocs->meta->message;
  329. endif;
  330. if ($response->status == 'failed'):
  331. return 'Please make sure module configured successfully';
  332. endif;
  333. if ($response->ocs->meta->status == 'ok'):
  334. # Add Email Address to nextcloud Account
  335. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  336. $post = array('key' => 'email', 'value' => $params['clientsdetails']['email']);
  337. nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "put", $post);
  338. #######################################
  339. # User without Group
  340. if ($params['configoption15']) { # Condition to create user without group
  341. $responseg->ocs->meta->status = 'ok';
  342. } else {
  343. // $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME] . '/groups');
  344. // $post = array('groupid' => $groupname);
  345. // $responseg = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
  346. //
  347. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl , "whmcsintegration/togglegroups?format=json");
  348. $post = array("userid" => $params["customfields"][$USERNAME], "groups" => json_encode(array($groupname)));
  349. $responseg = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
  350. # log module call 2
  351. $requeststring = $post;
  352. $responsedata = array();
  353. $processeddata = (array) $responseg;
  354. $replacevars = array();
  355. logModuleCall("nextcloud", "create account => assign group", $requeststring, $responsedata, $processeddata, $replacevars);
  356. }
  357. if (!empty($groupname) || $params['configoption15']): # Condition afer user added to group success
  358. //if ($responseg->ocs->meta->status == 'ok'): # Condition afer user added to group success
  359. # Make user group admin
  360. if ($params['configoption18']) {
  361. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME] . '/subadmins');
  362. $post = array('groupid' => $groupname);
  363. nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
  364. }
  365. # #####################
  366. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  367. $post = array('key' => 'quota', 'value' => $Quota);
  368. $responseq = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "put", $post);
  369. if ($responseq->ocs->meta->status == 'ok'):
  370. /*
  371. *
  372. * Clear service username and password
  373. *
  374. */
  375. Capsule::update("update tblhosting set username = '', password='' where id='".$params["serviceid"]."'");
  376. /*
  377. * Send nextcloud account welcome email to user
  378. */
  379. $command = "sendemail";
  380. $adminuser = nextcloud_getAdminId();
  381. $values["messagename"] = trim($params['configoption20']);
  382. $values["id"] = $params['serviceid'];
  383. $values["customvars"] = base64_encode(serialize(array("domain" => $params["serverhostname"], "username" => $params["customfields"][$USERNAME], "password" => $params["customfields"][$PASSWORD])));
  384. localAPI($command, $values, $adminuser);
  385. $result = 'success';
  386. else:
  387. $result = "Error occurred while adding quota for user";
  388. endif;
  389. # log module call 3
  390. $requeststring = $post;
  391. $responsedata = array();
  392. $processeddata = (array) $responseq;
  393. $replacevars = array();
  394. logModuleCall("nextcloud", "create account => assign quota", $requeststring, $responsedata, $processeddata, $replacevars);
  395. else:
  396. $result = "Error occurred while adding user to group";
  397. endif;
  398. else:
  399. $result = "Error occurred while creating a new user";
  400. endif;
  401. return $result;
  402. }
  403. function nextcloud_TerminateAccount($params) {
  404. $encoding = (empty($params['configoption11'])) ? false : true;
  405. $result = Capsule::table('tblhosting')->select('domainstatus')->where('id',$params['serviceid'])->get();
  406. $data = (array) $result[0];
  407. if ('Terminated' == $data['domainstatus']) {
  408. return 'Your current status of service is already Terminated';
  409. }
  410. $action = 'delete';
  411. # Username
  412. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  413. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  414. $cfData = explode('|',$USERNAME);
  415. if(count($cfData)>=2){
  416. $USERNAME = $cfData[0];
  417. }
  418. # API URL
  419. $apiurl = $params['configoption3'];
  420. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  421. $serverSecure = 'https://';
  422. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  423. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action);
  424. if ($response->ocs->meta->status == 'ok') {
  425. $result = 'success';
  426. } else {
  427. $result = 'Your service does not terminated successfully';
  428. }
  429. # log module call
  430. $requeststring = $post;
  431. $responsedata = array();
  432. $processeddata = (array) $response;
  433. $replacevars = array();
  434. logModuleCall("nextcloud", "terminate account", $requeststring, $responsedata, $processeddata, $replacevars);
  435. return $result;
  436. }
  437. function nextcloud_SuspendAccount($params) {
  438. $encoding = (empty($params['configoption11'])) ? false : true;
  439. $result = Capsule::select("select domainstatus from tblhosting where id='".$params['serviceid']."' ");
  440. if ('Suspended' == $result[0]->domainstatus) {
  441. return 'Your current status of service is already Suspended';
  442. }
  443. $action = 'post';
  444. # Username
  445. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  446. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  447. $cfData = explode('|',$USERNAME);
  448. if(count($cfData)>=2){
  449. $USERNAME = $cfData[0];
  450. }
  451. if ($params['serversecure'] == 'on')
  452. $serverSecure = 'https://';
  453. else
  454. $serverSecure = 'http://';
  455. # API URL
  456. //$apiurl = '/ocs/v2.php/apps/';
  457. $apiAppurl = $params['configoption21'];
  458. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl, $params["configoption2"], '/suspenduser');
  459. $post = array("userid" => $params["customfields"][$USERNAME]);
  460. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
  461. if ($response->ocs->meta->status == 'ok'):
  462. $result = 'success';
  463. else:
  464. $result = 'Your service does not suspended successfully';
  465. endif;
  466. # log module call
  467. $requeststring = $post;
  468. $responsedata = array();
  469. $processeddata = (array) $response;
  470. $replacevars = array();
  471. logModuleCall("nextcloud", "suspend account", $requeststring, $responsedata, $processeddata, $replacevars);
  472. return $result;
  473. }
  474. function nextcloud_UnsuspendAccount($params) {
  475. $encoding = (empty($params['configoption11'])) ? false : true;
  476. $result = Capsule::select("select domainstatus from tblhosting where id='".$params['serviceid']."' ");
  477. if ('Suspended' != $result[0]->domainstatus) {
  478. return 'Your current status of service is not suspended, Only suspended service can be unsuspended';
  479. }
  480. $action = 'post';
  481. # Username
  482. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  483. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  484. $cfData = explode('|',$USERNAME);
  485. if(count($cfData)>=2){
  486. $USERNAME = $cfData[0];
  487. }
  488. if ($params['serversecure'] == 'on')
  489. $serverSecure = 'https://';
  490. else
  491. $serverSecure = 'http://';
  492. # API URL
  493. //$apiurl = '/ocs/v2.php/apps/';
  494. $apiAppurl = $params['configoption21'];
  495. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl, $params["configoption2"], '/unsuspenduser');
  496. $post = array("userid" => $params["customfields"][$USERNAME]);
  497. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
  498. if ($response->ocs->meta->status == 'ok'):
  499. $result = 'success';
  500. else:
  501. $result = 'Your module command failed to unsuspended your service';
  502. endif;
  503. # log module call
  504. $requeststring = $post;
  505. $responsedata = array();
  506. $processeddata = (array) $response;
  507. $replacevars = array();
  508. logModuleCall("nextcloud", "unsuspend account", $requeststring, $responsedata, $processeddata, $replacevars);
  509. return $result;
  510. }
  511. function nextcloud_ChangePassword($params) {
  512. if (nextcloud_checkLicense_server_file() != 'Active') {
  513. return "Your license is " . nextcloud_checkLicense_server_file();
  514. }
  515. $encoding = (empty($params['configoption11'])) ? false : true;
  516. # Username
  517. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  518. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  519. $cfData = explode('|',$USERNAME);
  520. if(count($cfData)>=2){
  521. $USERNAME = $cfData[0];
  522. }
  523. # Password
  524. $PASSWORD = substr($params['configoption6'], strpos($params['configoption6'], ':') + 1);
  525. $PASSWORD = nextcloud_character_encoding($PASSWORD, $encoding);
  526. $PASSWORD02 = $PASSWORD;
  527. $cfData = explode('|',$PASSWORD);
  528. if(count($cfData)>=2){
  529. $PASSWORD = $cfData[0];
  530. }
  531. # API URL
  532. $apiurl = $params['configoption3'];
  533. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  534. if ($params['serversecure'] == 'on')
  535. $serverSecure = 'https://';
  536. else
  537. $serverSecure = 'http://';
  538. $P = $params["customfields"][$PASSWORD];
  539. $action = 'put';
  540. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  541. $post = array('key' => 'password', 'value' => $params["password"]);
  542. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
  543. if ($response->ocs->meta->status == 'ok'):
  544. 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')");
  545. $result = 'success';
  546. else:
  547. $result = $response->ocs->meta->message;
  548. endif;
  549. # log module call
  550. $requeststring = $post;
  551. $responsedata = array();
  552. $processeddata = (array) $response;
  553. $replacevars = array();
  554. logModuleCall("nextcloud", "change password", $requeststring, $responsedata, $processeddata, $replacevars);
  555. return $result;
  556. }
  557. function nextcloud_ChangePackage($params) { # Only upgrade/downgrade quota
  558. $encoding = (empty($params['configoption11'])) ? false : true;
  559. # Username
  560. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  561. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  562. $cfData = explode('|',$USERNAME);
  563. if(count($cfData)>=2){
  564. $USERNAME = $cfData[0];
  565. }
  566. # Server Name
  567. $servername = $params['configoption7'];
  568. $servername = nextcloud_character_encoding($servername, $encoding);
  569. # API URL
  570. $apiurl = $params['configoption3'];
  571. $apiAppurl = $params['configoption21'];
  572. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  573. if ($params['serversecure'] == 'on')
  574. $serverSecure = 'https://';
  575. else
  576. $serverSecure = 'http://';
  577. if ($params["serverusername"] == "" || $params["serverpassword"] == "" || $params["serverhostname"] == "") {
  578. return "Please check your server configuration or Server is not assinged to the module";
  579. }
  580. if ($params['configoption13']) {
  581. $groupname = $params['configoption8'];
  582. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiAppurl , "whmcsintegration/togglegroups?format=json");
  583. $post = array("userid" => $params["customfields"][$USERNAME], "groups" => json_encode(array($groupname)));
  584. $responseg = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "post", $post);
  585. }
  586. if ($params["configoption12"] == 'on') { # Quota set by admin
  587. $Quota = $params["configoption10"] . " " . $params["configoption14"];
  588. } else { # Quota set by customer
  589. if($params['configoptions']['Quota in GB'] != 0){
  590. $QUOTA = substr($params['configoption10'], strpos($params['configoption10'], ':') + 1);
  591. $QUOTA = nextcloud_character_encoding($QUOTA, $encoding);
  592. $cfData = explode('|',$QUOTA);
  593. if(count($cfData)>=2){
  594. $QUOTA = $cfData[0];
  595. }
  596. $Quota = $params['configoptions'][$QUOTA] . " " . $params['configoption14'];
  597. }
  598. else{
  599. $query = Capsule::table('tblproductconfiglinks')->select('gid')->where('pid',$params['pid'])->get();
  600. $config_group_id = $query[0]->gid;
  601. $query2 = Capsule::table('tblproductconfigoptions')->select('id','qtymaximum')->where('gid',$config_group_id)->get();
  602. Capsule::table('tblhostingconfigoptions')->where('relid',$params['serviceid'])->where('configid',$query2[0]->id)->update(['qty' =>$query2[0]->qtymaximum]);;
  603. $Quota = $query2[0]->qtymaximum . " " . $params['configoption14'];
  604. }
  605. }
  606. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  607. $post = array('key' => 'quota', 'value' => $Quota);
  608. //echo "----------------".$params['configoptions']['Quota in GB'];
  609. //die();
  610. $responseq = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], "put", $post);
  611. logModuleCall("nextcloud", "change package", $post, (array) $responseq);
  612. if ($responseq->ocs->meta->status == 'ok'):
  613. return 'success';
  614. else:
  615. return 'Error occurred while adding quota for user';
  616. endif;
  617. }
  618. function nextcloud_getLang($params) {
  619. global $CONFIG;
  620. if (!empty($_SESSION['Language']))
  621. $language = strtolower($_SESSION['Language']);
  622. else if (strtolower($params['clientsdetails']['language']) != '')
  623. $language = strtolower($params['clientsdetails']['language']);
  624. else
  625. $language = $CONFIG['Language'];
  626. $langfilename = dirname(__FILE__) .'/lang/'. $language . '.php';
  627. if (file_exists($langfilename))
  628. require_once($langfilename);
  629. else
  630. require_once(dirname(__FILE__) . '/lang/english.php');
  631. if (isset($lang))
  632. return $lang;
  633. }
  634. function nextcloud_ClientArea($params) {
  635. if (nextcloud_checkLicense_server_file() != 'Active') {
  636. return "Your license is " . nextcloud_checkLicense_server_file();
  637. }
  638. $langVar = nextcloud_getLang($params);
  639. if ($params['serversecure'] == 'on')
  640. $serverSecure = 'https://';
  641. else
  642. $serverSecure = 'http://';
  643. $encoding = (empty($params['configoption11'])) ? false : true;
  644. if(empty($_REQUEST))
  645. {
  646. $code='';
  647. return $code;
  648. }
  649. # Username
  650. $USERNAME = substr($params['configoption4'], strpos($params['configoption4'], ':') + 1);
  651. $USERNAME = nextcloud_character_encoding($USERNAME, $encoding);
  652. $cfData = explode('|',$USERNAME);
  653. if(count($cfData)>=2){
  654. $USERNAME = $cfData[0];
  655. }
  656. # Password
  657. $PASSWORD = substr($params['configoption6'], strpos($params['configoption6'], ':') + 1);
  658. $PASSWORD = nextcloud_character_encoding($PASSWORD, $encoding);
  659. $cfData = explode('|',$PASSWORD);
  660. if(count($cfData)>=2){
  661. $PASSWORD = $cfData[0];
  662. }
  663. # API URL
  664. $apiurl = $params['configoption3'];
  665. $apiAppurl = $params['configoption21'];
  666. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  667. # Login button value
  668. $nextcloudlogin = $params['configoption9'];
  669. $nextcloudlogin = nextcloud_character_encoding($nextcloudlogin, $encoding);
  670. //$autologin = '<form action="' . $serverSecure . $params['serverhostname'] . $apiAppurl.$params["configoption2"].'/autologinuser" method="post" target="_blank" name="login">
  671. $autologin = '<form action="' . $serverSecure . $params['serverhostname'].'/index.php/login" method="post" target="_blank" name="login">
  672. <input type="hidden" name="username" value="' . $params["customfields"][$USERNAME] . '" />
  673. <input type="hidden" name="password" value="' . $params["customfields"][$PASSWORD] . '" />
  674. <input type="submit" value="' . $nextcloudlogin . '" class="btn btn-warning modulebutton" />
  675. </form>';
  676. if (isset($_POST["nextcloud_email"])) {
  677. # API URL
  678. $appapiurl = $params['configoption21'];
  679. if (empty($_POST["nextcloud_email"])) {
  680. $action = 'post';
  681. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $appapiurl, $params["configoption2"], '/deluservalue');
  682. $post = array('userid' => $params["customfields"][$USERNAME], 'app' => 'settings', 'key' => 'email');
  683. $res = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
  684. } else {
  685. $action = 'put';
  686. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  687. $post = array('key' => 'email', 'value' => trim($_POST["nextcloud_email"]));
  688. $res = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action, $post);
  689. }
  690. # log module call
  691. $requeststring = $post;
  692. $responsedata = array();
  693. $processeddata = (array) $res;
  694. $replacevars = array();
  695. logModuleCall("nextcloud", "Change Email Address", $requeststring, $responsedata, $processeddata, $replacevars);
  696. }
  697. $action = 'get';
  698. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, 'users/' . $params["customfields"][$USERNAME]);
  699. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action);
  700. $email = $response->ocs->data->email;
  701. $code = '<form method="post" action="clientarea.php?action=productdetails&id=' . $params["serviceid"] . '"><div class="panel panel-default">
  702. <div class="panel-heading">
  703. <h3 class="panel-title">'.$langVar['nextcloudSettings'].'</h3>
  704. </div>
  705. <div class="panel-body text-center">
  706. <div class="row">
  707. <div class="col-sm-3 col-xs-6"><div class="form-group">'.$langVar['EmailAddress'].'</div></div>
  708. <div class="col-sm-6 col-xs-6">
  709. <div class="form-group"><input type="text" name="nextcloud_email" value="' . $email . '" class="form-control" placeholder="'.$langVar['nextcloudEmailAddress'].'"></div>
  710. </div></div>
  711. <div class="row">
  712. <div class="col-sm-12 col-xs-12">
  713. <div class="form-group"><input type="submit" class="btn btn-primary" value="'.$langVar['ChangenextcloudEmailAddress'].'"></div></div>
  714. </div>
  715. </div></div></form>';
  716. $code .= '<div class="row"><div class="col-sm-12 col-xs-12">
  717. <div class="form-group">' . $autologin . '</div></div></div>';
  718. return $code;
  719. }
  720. function nextcloud_AdminLink($params) {
  721. $action = 'get';
  722. if ($params['serversecure'] == 'on')
  723. $serverSecure = 'https://';
  724. else
  725. $serverSecure = 'http://';
  726. # API URL
  727. $apiurl = $params['configoption3'];
  728. $apiAppurl = $params['configoption21'];
  729. //$apiurl = str_replace('/', DIRECTORY_SEPARATOR, $apiurl);
  730. $href = nextcloud_API_URL($serverSecure, $params["serverhostname"], $apiurl, $APP_ID, 'groups');
  731. $response = nextcloud_Send($href, $params["serverusername"], $params["serverpassword"], $action);
  732. if ($response->status == 'failed'):
  733. $value = 'Enable nextcloud APP';
  734. else:
  735. $value = 'Disable nextcloud APP';
  736. endif;
  737. $code = '<form action="' . $serverSecure . $params["serverhostname"] . '" method="post" target="_blank" name="login">
  738. <input type="hidden" name="user" value="' . $params["serverusername"] . '" />
  739. <input type="hidden" name="password" value="' . $params["serverpassword"] . '" />
  740. <input type="submit" value="' . $value . '" />
  741. </form>';
  742. return $code;
  743. }
  744. ###########################################################################################################################
  745. ################################################## Custom Functions #######################################################
  746. ###########################################################################################################################
  747. function nextcloud_character_encoding($str, $encoding) {
  748. $string = ($encoding) ? nextcloud_Encoding::fixUTF8($str) : $str;
  749. return $string;
  750. }
  751. function nextcloud_getAdminId() {
  752. $Query = Capsule::select("SELECT id FROM `tbladmins` LIMIT 1");
  753. $Id = $Query[0]->id;
  754. return $Id;
  755. }
  756. function nextcloud_customfieldsConfigurableOptions($productid) {
  757. $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);
  758. $result = Capsule::select($query);
  759. $numberOfOptions = 0;
  760. $optionsAr = array();
  761. foreach($result as $key => $optionValue02) {
  762. $optionValue = (array) $optionValue02;
  763. $optionsAr[] = $optionValue['ufieldname'];
  764. $numberOfOptions++;
  765. }
  766. $options = implode(",", $optionsAr);
  767. return array('result' => 'success', 'availoptions' => $numberOfOptions, 'options' => $options);
  768. }
  769. function nextcloud_addCustomfieldsConfigurableFields($productid, $create_configurationoptions, $quotaunits, $enablegroup, $customgroup, $groups) {
  770. ######################## CREATE CUSTOMFIELDS ######################
  771. $customfieldresult = Capsule::table('tblcustomfields')->where('type','product')->where('relid',$productid)->count();
  772. $customfields = array(
  773. "Username" => "text",
  774. "Password" => "password"
  775. );
  776. $addcustomfielddesc = '';
  777. $addfieldoptions = '';
  778. $addregexpr = '';
  779. $addadminonly = '';
  780. $addrequired = 'on';
  781. $addshoworder = 'on';
  782. $addshowinvoice = '';
  783. $addsortorder = '';
  784. foreach ($customfields as $addfieldname => $addfieldtype) {
  785. if ($addfieldtype == "dropdown") {
  786. $addfieldoptions = implode(",", $groups);
  787. }
  788. if ($addfieldtype == "password") {
  789. $addcustomfielddesc = "Password must be at least 8 characters, no more than 18 characters.";
  790. $addregexpr = "/^.{8,}$/";
  791. } else {
  792. $addcustomfielddesc = "";
  793. $addregexpr = "";
  794. }
  795. if ($customfieldresult == 0) {
  796. Capsule::table('tblcustomfields')->insert(
  797. [
  798. 'type' => 'product',
  799. 'relid' => $productid,
  800. 'fieldname' => $addfieldname,
  801. 'fieldtype' => $addfieldtype,
  802. 'description' => $addcustomfielddesc,
  803. 'fieldoptions' => $addfieldoptions,
  804. 'regexpr' => html_entity_decode($addregexpr),
  805. 'adminonly' => $addadminonly,
  806. 'required' => $addrequired,
  807. 'showorder' => $addshoworder,
  808. 'showinvoice' => $addshowinvoice,
  809. 'sortorder' => $addsortorder,
  810. ]
  811. );
  812. } else {
  813. $customfieldcount = Capsule::table("tblcustomfields")->where('type','product')->where('relid',$productid)->where("fieldname",$addfieldname)->count();
  814. if($customfieldcount == 0){
  815. Capsule::table('tblcustomfields')->insert(
  816. [
  817. 'type' => 'product',
  818. 'relid' => $productid,
  819. 'fieldname' => $addfieldname,
  820. 'fieldtype' => $addfieldtype,
  821. 'description' => $addcustomfielddesc,
  822. 'fieldoptions' => $addfieldoptions,
  823. 'regexpr' => html_entity_decode($addregexpr),
  824. 'adminonly' => $addadminonly,
  825. 'required' => $addrequired,
  826. 'showorder' => $addshoworder,
  827. 'showinvoice' => $addshowinvoice,
  828. 'sortorder' => $addsortorder,
  829. ]
  830. );
  831. } else {
  832. Capsule::table("tblcustomfields")->where('type','product')->where('relid',$productid)->where("fieldname",$addfieldname)->update(
  833. [
  834. 'type' => 'product',
  835. 'relid' => $productid,
  836. 'fieldname' => $addfieldname,
  837. 'fieldtype' => $addfieldtype,
  838. 'description' => $addcustomfielddesc,
  839. 'fieldoptions' => $addfieldoptions,
  840. 'regexpr' => html_entity_decode($addregexpr),
  841. 'adminonly' => $addadminonly,
  842. 'required' => $addrequired,
  843. 'showorder' => $addshoworder,
  844. 'showinvoice' => $addshowinvoice,
  845. 'sortorder' => $addsortorder,
  846. ]
  847. );
  848. }
  849. }
  850. }
  851. if ($create_configurationoptions) {
  852. nextcloud_unlinkproductconfigoptions($productid);
  853. } else {
  854. ######################## CONFIGURABLE OPTION #####################
  855. $addconfigrablegroupname = "nextcloud Storage" . $productid;
  856. $addconfigurabledescription = "Quota in " . $quotaunits;
  857. $addconfigurableoptionname = "Quota in " . $quotaunits;
  858. $configurableoptionresult = Capsule::table('tblproductconfiglinks')->where('pid',$productid)->count();
  859. $configurableoptionresultbynameR = Capsule::table('tblproductconfiggroups')->where('name',$addconfigrablegroupname)->count();
  860. $configurableoptionresultbyname = Capsule::select("select id from tblproductconfiggroups where name='".$addconfigrablegroupname."'");
  861. $configurableoptionresultbynamedata["id"] = $configurableoptionresultbyname[0]->id;
  862. if($configurableoptionresultbynameR > 0 && $configurableoptionresult == 0){
  863. Capsule::table('tblproductconfiglinks')->insert(
  864. [
  865. 'gid' => $configurableoptionresultbynamedata["id"],
  866. 'pid' => $productid,
  867. ]
  868. );
  869. } else if ($configurableoptionresult == 0) {
  870. $configurablegroupid = Capsule::table('tblproductconfiggroups')->insertGetId(
  871. [
  872. 'name' => $addconfigrablegroupname,
  873. 'description' => $addconfigurabledescription,
  874. ]
  875. );
  876. Capsule::table('tblproductconfiglinks')->insertGetId(
  877. [
  878. 'gid' => $configurablegroupid,
  879. 'pid' => $productid,
  880. ]
  881. );
  882. $configid = Capsule::table('tblproductconfigoptions')->insertGetId(
  883. [
  884. 'gid' => $configurablegroupid,
  885. 'optionname' => $addconfigurableoptionname,
  886. 'optiontype' => '4',
  887. 'qtyminimum' => '1',
  888. 'qtymaximum' => '10',
  889. 'order' => '',
  890. 'hidden' => '',
  891. ]
  892. );
  893. $tblpricing_rel_id = Capsule::table('tblproductconfigoptionssub')->insertGetId(
  894. [
  895. 'configid' => $configid,
  896. 'optionname' => '',
  897. 'sortorder' => '',
  898. 'hidden' => ''
  899. ]
  900. );
  901. $result = Capsule::table('tblcurrencies')->get();
  902. foreach($result as $data) {
  903. $curr_id = $data->id;
  904. $curr_code = $data->code;
  905. $currenciesarray[$curr_id] = $curr_code;
  906. }
  907. foreach ($currenciesarray as $curr_id => $currency) {
  908. Capsule::table('tblpricing')->insertGetId(
  909. [
  910. 'type' => 'configoptions',
  911. 'currency' => $curr_id,
  912. 'relid' => $tblpricing_rel_id,
  913. 'msetupfee' => '',
  914. 'qsetupfee' => '',
  915. 'ssetupfee' => '',
  916. 'asetupfee' => '',
  917. 'bsetupfee' => '',
  918. 'tsetupfee' => '',
  919. 'monthly' => '',
  920. 'quarterly' => '',
  921. 'semiannually' => '',
  922. 'annually' => '',
  923. 'biennially' => '',
  924. 'triennially' => '',
  925. ]
  926. );
  927. }
  928. }
  929. ###########################################
  930. }
  931. }
  932. function nextcloud_unlinkproductconfigoptions($productid) {
  933. $addconfigrablegroupname = "nextcloud Storage" . $productid;
  934. $chkGroup = Capsule::table('tblproductconfiggroups')->where('name',$addconfigrablegroupname)->count();
  935. if($chkGroup!='0') {
  936. $query = Capsule::table('tblproductconfiglinks')->select('gid')->where('pid',$productid)->get();
  937. $config_group_id = $query[0]->gid;
  938. $query2 = Capsule::table('tblproductconfigoptions')->select('id')->where('gid',$config_group_id)->get();
  939. $config_id = $query2[0]->id;
  940. $query3 = Capsule::table('tblproductconfigoptionssub')->select('id')->where('configid',$config_id)->get();
  941. $pricing_rel_id = $query3[0]->id;
  942. if(!empty($pricing_rel_id)){
  943. Capsule::table('tblpricing')->where('type','configoptions')->where('relid',$pricing_rel_id)->delete();
  944. }
  945. if(!empty($pricing_rel_id)){
  946. Capsule::table('tblproductconfigoptionssub')->where('id',$config_id)->delete();
  947. }
  948. if(!empty($pricing_rel_id)){
  949. Capsule::table('tblproductconfigoptions')->where('gid',$config_group_id)->delete();
  950. }
  951. if(!empty($pricing_rel_id)){
  952. Capsule::table('tblproductconfiggroups')->where('id',$config_group_id)->delete();
  953. }
  954. if(!empty($pricing_rel_id)){
  955. Capsule::table('tblproductconfiglinks')->where('gid',$config_group_id)->delete();
  956. }
  957. }
  958. }
  959. ################################################################################################
  960. # 19.02.2015
  961. function nextcloud_addGroupCustomField($productid, $fieldname, $create_manageAdminGroup, $userwithoutgroup, $customgroup, $groups) {
  962. $group = substr($fieldname, strpos($fieldname, ':') + 1);
  963. if ($userwithoutgroup || $create_manageAdminGroup) {
  964. //$affectedRow = Capsule::table('tblcustomfields')->where('fieldname',$group)->where('fieldtype','dropdown')->where('type','product')->where('relid',$productid)->delete();
  965. $affectedRow = Capsule::delete("delete from tblcustomfields where relid='".$productid."' and type='product' and fieldname like 'Group%' ");
  966. // if ($affectedRow == 0) {
  967. // Capsule::table('tblcustomfields')->where('type','product')->where('relid',$productid)->delete();
  968. // }
  969. } elseif ((!$create_manageAdminGroup && !$userwithoutgroup) && !$customgroup) {
  970. // if (!strpos($fieldname, ":")) {
  971. $avail_group_result = Capsule::select("SELECT count(*) as `group_field` FROM `tblcustomfields` WHERE `fieldtype`='dropdown' AND `type`='product' AND `relid`=" . $productid);
  972. $avail_group_data = (array) $avail_group_result[0];
  973. if ($avail_group_data['group_field'] == 0) {
  974. $addfieldname = "Group";
  975. $addfieldtype = "dropdown";
  976. $addcustomfielddesc = '';
  977. $addfieldoptions = implode(",", $groups);
  978. $addregexpr = '';
  979. $addadminonly = '';
  980. $addrequired = 'on';
  981. $addshoworder = 'on';
  982. $addshowinvoice = '';
  983. $addsortorder = '';
  984. Capsule::table('tblcustomfields')->insertGetId(
  985. [
  986. 'type' => 'product',
  987. 'relid' => $productid,
  988. 'fieldname' => $addfieldname,
  989. 'fieldtype' => $addfieldtype,
  990. 'description' => $addcustomfielddesc,
  991. 'fieldoptions' => $addfieldoptions,
  992. 'regexpr' => html_entity_decode($addregexpr),
  993. 'adminonly' => $addadminonly,
  994. 'required' => $addrequired,
  995. 'showorder' => $addshoworder,
  996. 'showinvoice' => $addshowinvoice,
  997. 'sortorder' => $addsortorder,
  998. ]
  999. );
  1000. }
  1001. // }
  1002. }
  1003. }
  1004. function nextcloud_remove_utf8bom($text) {
  1005. $bom = pack('H*', 'EFBBBF');
  1006. $text = preg_replace("/^$bom/", '', $text);
  1007. return $text;
  1008. }
  1009. function nextcloud_Send($href, $username, $password, $action, $post = array()) {
  1010. $postdata = http_build_query($post);
  1011. $ch = curl_init();
  1012. if (strtoupper($action) == 'POST'):
  1013. curl_setopt($ch, CURLOPT_POST, true);
  1014. if ($postdata)
  1015. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  1016. endif;
  1017. if (strtoupper($action) == 'PUT'):
  1018. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  1019. if ($postdata)
  1020. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  1021. endif;
  1022. if (strtoupper($action) == 'GET'):
  1023. curl_setopt($ch, CURLOPT_HTTPGET, true);
  1024. endif;
  1025. if (strtoupper($action) == 'DELETE'):
  1026. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  1027. endif;
  1028. curl_setopt($ch, CURLOPT_URL, $href);
  1029. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
  1030. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  1031. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json","OCS-APIRequest: true",'content-type: application/x-www-form-urlencoded'));
  1032. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1033. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1034. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1035. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  1036. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  1037. $result_json = curl_exec($ch);
  1038. curl_close($ch);
  1039. //print_r($result_json);die();
  1040. $result_bom = nextcloud_remove_utf8bom($result_json);
  1041. $result = json_decode($result_bom);
  1042. return($result);
  1043. }
  1044. function nextcloud_API_URL($serverSecure, $host, $apiurl, $app_id = NULL, $action = '') {
  1045. $url = $serverSecure . $host . $apiurl . $app_id . $action . '?format=json';
  1046. return $url;
  1047. }
  1048. ######################################## Encoding Class ######################################33
  1049. class nextcloud_Encoding {
  1050. const ICONV_TRANSLIT = "TRANSLIT";
  1051. const ICONV_IGNORE = "IGNORE";
  1052. const WITHOUT_ICONV = "";
  1053. protected static $win1252ToUtf8 = array(
  1054. 128 => "\xe2\x82\xac",
  1055. 130 => "\xe2\x80\x9a",
  1056. 131 => "\xc6\x92",
  1057. 132 => "\xe2\x80\x9e",
  1058. 133 => "\xe2\x80\xa6",
  1059. 134 => "\xe2\x80\xa0",
  1060. 135 => "\xe2\x80\xa1",
  1061. 136 => "\xcb\x86",
  1062. 137 => "\xe2\x80\xb0",
  1063. 138 => "\xc5\xa0",
  1064. 139 => "\xe2\x80\xb9",
  1065. 140 => "\xc5\x92",
  1066. 142 => "\xc5\xbd",
  1067. 145 => "\xe2\x80\x98",
  1068. 146 => "\xe2\x80\x99",
  1069. 147 => "\xe2\x80\x9c",
  1070. 148 => "\xe2\x80\x9d",
  1071. 149 => "\xe2\x80\xa2",
  1072. 150 => "\xe2\x80\x93",
  1073. 151 => "\xe2\x80\x94",
  1074. 152 => "\xcb\x9c",
  1075. 153 => "\xe2\x84\xa2",
  1076. 154 => "\xc5\xa1",
  1077. 155 => "\xe2\x80\xba",
  1078. 156 => "\xc5\x93",
  1079. 158 => "\xc5\xbe",
  1080. 159 => "\xc5\xb8"
  1081. );
  1082. protected static $brokenUtf8ToUtf8 = array(
  1083. "\xc2\x80" => "\xe2\x82\xac",
  1084. "\xc2\x82" => "\xe2\x80\x9a",
  1085. "\xc2\x83" => "\xc6\x92",
  1086. "\xc2\x84" => "\xe2\x80\x9e",
  1087. "\xc2\x85" => "\xe2\x80\xa6",
  1088. "\xc2\x86" => "\xe2\x80\xa0",
  1089. "\xc2\x87" => "\xe2\x80\xa1",
  1090. "\xc2\x88" => "\xcb\x86",
  1091. "\xc2\x89" => "\xe2\x80\xb0",
  1092. "\xc2\x8a" => "\xc5\xa0",
  1093. "\xc2\x8b" => "\xe2\x80\xb9",
  1094. "\xc2\x8c" => "\xc5\x92",
  1095. "\xc2\x8e" => "\xc5\xbd",
  1096. "\xc2\x91" => "\xe2\x80\x98",
  1097. "\xc2\x92" => "\xe2\x80\x99",
  1098. "\xc2\x93" => "\xe2\x80\x9c",
  1099. "\xc2\x94" => "\xe2\x80\x9d",
  1100. "\xc2\x95" => "\xe2\x80\xa2",
  1101. "\xc2\x96" => "\xe2\x80\x93",
  1102. "\xc2\x97" => "\xe2\x80\x94",
  1103. "\xc2\x98" => "\xcb\x9c",
  1104. "\xc2\x99" => "\xe2\x84\xa2",
  1105. "\xc2\x9a" => "\xc5\xa1",
  1106. "\xc2\x9b" => "\xe2\x80\xba",
  1107. "\xc2\x9c" => "\xc5\x93",
  1108. "\xc2\x9e" => "\xc5\xbe",
  1109. "\xc2\x9f" => "\xc5\xb8"
  1110. );
  1111. protected static $utf8ToWin1252 = array(
  1112. "\xe2\x82\xac" => "\x80",
  1113. "\xe2\x80\x9a" => "\x82",
  1114. "\xc6\x92" => "\x83",
  1115. "\xe2\x80\x9e" => "\x84",
  1116. "\xe2\x80\xa6" => "\x85",
  1117. "\xe2\x80\xa0" => "\x86",
  1118. "\xe2\x80\xa1" => "\x87",
  1119. "\xcb\x86" => "\x88",
  1120. "\xe2\x80\xb0" => "\x89",
  1121. "\xc5\xa0" => "\x8a",
  1122. "\xe2\x80\xb9" => "\x8b",
  1123. "\xc5\x92" => "\x8c",
  1124. "\xc5\xbd" => "\x8e",
  1125. "\xe2\x80\x98" => "\x91",
  1126. "\xe2\x80\x99" => "\x92",
  1127. "\xe2\x80\x9c" => "\x93",
  1128. "\xe2\x80\x9d" => "\x94",
  1129. "\xe2\x80\xa2" => "\x95",
  1130. "\xe2\x80\x93" => "\x96",
  1131. "\xe2\x80\x94" => "\x97",
  1132. "\xcb\x9c" => "\x98",
  1133. "\xe2\x84\xa2" => "\x99",
  1134. "\xc5\xa1" => "\x9a",
  1135. "\xe2\x80\xba" => "\x9b",
  1136. "\xc5\x93" => "\x9c",
  1137. "\xc5\xbe" => "\x9e",
  1138. "\xc5\xb8" => "\x9f"
  1139. );
  1140. static function toUTF8($text) {
  1141. if (is_array($text)) {
  1142. foreach ($text as $k => $v) {
  1143. $text[$k] = self::toUTF8($v);
  1144. }
  1145. return $text;
  1146. } elseif (is_string($text)) {
  1147. if (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload')) & 2) {
  1148. $max = mb_strlen($text, '8bit');
  1149. } else {
  1150. $max = strlen($text);
  1151. }
  1152. $buf = "";
  1153. for ($i = 0; $i < $max; $i++) {
  1154. $c1 = $text{$i};
  1155. if ($c1 >= "\xc0") { //Should be converted to UTF8, if it's not UTF8 already
  1156. $c2 = $i + 1 >= $max ? "\x00" : $text{$i + 1};
  1157. $c3 = $i + 2 >= $max ? "\x00" : $text{$i + 2};
  1158. $c4 = $i + 3 >= $max ? "\x00" : $text{$i + 3};
  1159. if ($c1 >= "\xc0" & $c1 <= "\xdf") { //looks like 2 bytes UTF8
  1160. if ($c2 >= "\x80" && $c2 <= "\xbf") { //yeah, almost sure it's UTF8 already
  1161. $buf .= $c1 . $c2;
  1162. $i++;
  1163. } else { //not valid UTF8. Convert it.
  1164. $cc1 = (chr(ord($c1) / 64) | "\xc0");
  1165. $cc2 = ($c1 & "\x3f") | "\x80";
  1166. $buf .= $cc1 . $cc2;
  1167. }
  1168. } elseif ($c1 >= "\xe0" & $c1 <= "\xef") { //looks like 3 bytes UTF8
  1169. if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf") { //yeah, almost sure it's UTF8 already
  1170. $buf .= $c1 . $c2 . $c3;
  1171. $i = $i + 2;
  1172. } else { //not valid UTF8. Convert it.
  1173. $cc1 = (chr(ord($c1) / 64) | "\xc0");
  1174. $cc2 = ($c1 & "\x3f") | "\x80";
  1175. $buf .= $cc1 . $cc2;
  1176. }
  1177. } elseif ($c1 >= "\xf0" & $c1 <= "\xf7") { //looks like 4 bytes UTF8
  1178. if ($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf") { //yeah, almost sure it's UTF8 already
  1179. $buf .= $c1 . $c2 . $c3 . $c4;
  1180. $i = $i + 3;
  1181. } else { //not valid UTF8. Convert it.
  1182. $cc1 = (chr(ord($c1) / 64) | "\xc0");
  1183. $cc2 = ($c1 & "\x3f") | "\x80";
  1184. $buf .= $cc1 . $cc2;
  1185. }
  1186. } else { //doesn't look like UTF8, but should be converted
  1187. $cc1 = (chr(ord($c1) / 64) | "\xc0");
  1188. $cc2 = (($c1 & "\x3f") | "\x80");
  1189. $buf .= $cc1 . $cc2;
  1190. }
  1191. } elseif (($c1 & "\xc0") == "\x80") { // needs conversion
  1192. if (isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases
  1193. $buf .= self::$win1252ToUtf8[ord($c1)];
  1194. } else {
  1195. $cc1 = (chr(ord($c1) / 64) | "\xc0");
  1196. $cc2 = (($c1 & "\x3f") | "\x80");
  1197. $buf .= $cc1 . $cc2;
  1198. }
  1199. } else { // it doesn't need conversion
  1200. $buf .= $c1;
  1201. }
  1202. }
  1203. return $buf;
  1204. } else {
  1205. return $text;
  1206. }
  1207. }
  1208. static function toWin1252($text, $option = self::WITHOUT_ICONV) {
  1209. if (is_array($text)) {
  1210. foreach ($text as $k => $v) {
  1211. $text[$k] = self::toWin1252($v, $option);
  1212. }
  1213. return $text;
  1214. } elseif (is_string($text)) {
  1215. return static::utf8_decode($text, $option);
  1216. } else {
  1217. return $text;
  1218. }
  1219. }
  1220. static function toISO8859($text) {
  1221. return self::toWin1252($text);
  1222. }
  1223. static function toLatin1($text) {
  1224. return self::toWin1252($text);
  1225. }
  1226. static function fixUTF8($text, $option = self::WITHOUT_ICONV) {
  1227. if (is_array($text)) {
  1228. foreach ($text as $k => $v) {
  1229. $text[$k] = self::fixUTF8($v, $option);
  1230. }
  1231. return $text;
  1232. }
  1233. $last = "";
  1234. while ($last <> $text) {
  1235. $last = $text;
  1236. $text = self::toUTF8(static::utf8_decode($text, $option));
  1237. }
  1238. $text = self::toUTF8(static::utf8_decode($text, $option));
  1239. return $text;
  1240. }
  1241. static function UTF8FixWin1252Chars($text) {
  1242. // If you received an UTF-8 string that was converted from Windows-1252 as it was ISO8859-1
  1243. // (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it.
  1244. // See: http://en.wikipedia.org/wiki/Windows-1252
  1245. return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text);
  1246. }
  1247. static function removeBOM($str = "") {
  1248. if (substr($str, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
  1249. $str = substr($str, 3);
  1250. }
  1251. return $str;
  1252. }
  1253. public static function normalizeEncoding($encodingLabel) {
  1254. $encoding = strtoupper($encodingLabel);
  1255. $encoding = preg_replace('/[^a-zA-Z0-9\s]/', '', $encoding);
  1256. $equivalences = array(
  1257. 'ISO88591' => 'ISO-8859-1',
  1258. 'ISO8859' => 'ISO-8859-1',
  1259. 'ISO' => 'ISO-8859-1',
  1260. 'LATIN1' => 'ISO-8859-1',
  1261. 'LATIN' => 'ISO-8859-1',
  1262. 'UTF8' => 'UTF-8',
  1263. 'UTF' => 'UTF-8',
  1264. 'WIN1252' => 'ISO-8859-1',
  1265. 'WINDOWS1252' => 'ISO-8859-1'
  1266. );
  1267. if (empty($equivalences[$encoding])) {
  1268. return 'UTF-8';
  1269. }
  1270. return $equivalences[$encoding];
  1271. }
  1272. public static function encode($encodingLabel, $text) {
  1273. $encodingLabel = self::normalizeEncoding($encodingLabel);
  1274. if ($encodingLabel == 'UTF-8')
  1275. return Encoding::toUTF8($text);
  1276. if ($encodingLabel == 'ISO-8859-1')
  1277. return Encoding::toLatin1($text);
  1278. }
  1279. protected static function utf8_decode($text, $option) {
  1280. if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) {
  1281. $o = utf8_decode(
  1282. str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))
  1283. );
  1284. } else {
  1285. $o = iconv("UTF-8", "Windows-1252" . ($option == self::ICONV_TRANSLIT ? '//TRANSLIT' : ($option == self::ICONV_IGNORE ? '//IGNORE' : '')), $text);
  1286. }
  1287. return $o;
  1288. }
  1289. }
  1290. ?>