downloadclient.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. class myMisc extends misc
  3. {
  4. /**
  5. * Download zentao client.
  6. *
  7. * @access public
  8. * @param string $action
  9. * @param string $os
  10. * @return void
  11. */
  12. public function downloadClient($action = 'check', $os = '')
  13. {
  14. ini_set('memory_limit', '256M'); // Temporarily handle the problem that the ZenTao client file is too large.
  15. if($action == 'check')
  16. {
  17. $error = false;
  18. $errorInfo = '';
  19. $clientDir = $this->app->wwwRoot . 'data/client/' . $this->config->xuanxuan->version . '/';
  20. if(!is_dir($clientDir))
  21. {
  22. $result = mkdir($clientDir, 0755, true);
  23. if($result == false)
  24. {
  25. $error = true;
  26. $errorInfo = sprintf($this->lang->misc->client->errorInfo->dirNotExist, $clientDir, $clientDir);
  27. }
  28. }
  29. if(!is_writable($clientDir))
  30. {
  31. $error = true;
  32. $errorInfo = sprintf($this->lang->misc->client->errorInfo->dirNotWritable, $clientDir, $clientDir);
  33. }
  34. $this->view->error = $error;
  35. $this->view->errorInfo = $errorInfo;
  36. if(!$error) $this->locate($this->createLink('misc', 'downloadClient', "action=selectPackage"));
  37. }
  38. if($action == 'selectPackage')
  39. {
  40. $os = 'win64';
  41. $agentOS = helper::getOS();
  42. if(strpos($agentOS, 'Windows') !== false) $os = 'win64';
  43. if(strpos($agentOS, 'Linux') !== false) $os = 'linux64';
  44. if(strpos($agentOS, 'Mac') !== false) $os = 'mac64';
  45. $this->view->os = $os;
  46. /* Finish task #6990. */
  47. $releasedInDB = $this->dao->select('*')->from(TABLE_IM_CLIENT)->where('version')->eq($this->config->xuanxuan->version)->andWhere('status')->eq('released')->fetch();
  48. if($releasedInDB)
  49. {
  50. foreach(json_decode($releasedInDB->downloads) as $osKey => $link)
  51. {
  52. if(empty($link))
  53. {
  54. $osKey = strtolower(str_replace('zip', '', $osKey));
  55. if(isset($this->lang->misc->client->osList[$osKey]))
  56. {
  57. unset($this->lang->misc->client->osList[$osKey]);
  58. }
  59. elseif(strpos($osKey, 'mac') === 0)
  60. {
  61. unset($this->lang->misc->client->osList['mac64']);
  62. }
  63. }
  64. }
  65. }
  66. }
  67. if($action == 'getPackage')
  68. {
  69. $this->view->os = $os;
  70. $this->view->account = $this->app->user->account;
  71. }
  72. if($action == 'clearTmpPackage')
  73. {
  74. $account = $this->app->user->account;
  75. $tmpDir = $this->app->wwwRoot . 'data/client/' . "$account/";
  76. if(is_dir($tmpDir))
  77. {
  78. $zfile = $this->app->loadClass('zfile');
  79. $zfile->removeDir($tmpDir);
  80. }
  81. die(js::closeModal('parent.parent', 'this'));
  82. }
  83. if($action == 'downloadPackage')
  84. {
  85. ini_set('memory_limit', '1G');
  86. $account = $this->app->user->account;
  87. $clientDir = $this->app->wwwRoot . 'data/client/' . "$account/";
  88. $clientFile = $clientDir . 'zentaoclient.zip';
  89. $zipContent = file_get_contents($clientFile);
  90. if(is_dir($clientDir))
  91. {
  92. $zfile = $this->app->loadClass('zfile');
  93. $zfile->removeDir($clientDir);
  94. }
  95. $this->fetch('file', 'sendDownHeader', array('fileName' => "zentao_chat_client." . $os . '.zip', 'zip', $zipContent));
  96. }
  97. $this->view->action = $action;
  98. $this->display();
  99. }
  100. }