Guest User

/bt_v15/bt_app/bt_appNew.php

a guest
Aug 21st, 2014
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.81 KB | None | 0 0
  1. <?php require_once("../../config.php");
  2.  
  3. //who's logged in
  4. $guid = "";
  5. if(isset($_SESSION[APP_LOGGEDIN_COOKIE_NAME])) $guid = fnFormInput($_SESSION[APP_LOGGEDIN_COOKIE_NAME]);
  6.  
  7. //init user object
  8. $thisUser = new User($guid);
  9. $thisUser -> fnLoggedInReq($guid);
  10. $thisUser -> fnUpdateLastRequest($guid);
  11. $userName = fnFormOutput($thisUser->infoArray["firstName"] . " " . $thisUser->infoArray["lastName"]);
  12. $userSince = fnFromUTC($thisUser->infoArray["dateStampUTC"], $thisUser->infoArray["timeZone"], "m/d/Y");
  13.  
  14. //init page object
  15. $thisPage = new Page();
  16. $thisPage->pageTitle = "Create New Application";
  17.  
  18. //javascript files in header...
  19. $thisPage->scriptsInHeader = "bt_v15/bt_scripts/app_utilities.js";
  20.  
  21. //from may be admin (for cancel button)
  22. $from = fnGetReqVal("from", "", $myRequestVars);
  23. $cancelURL = fnGetSecureURL(APP_URL) . "/account";
  24. if(strtoupper($from) == "ADMIN") $cancelURL = fnGetSecureURL(APP_URL) . "/admin";
  25.  
  26.  
  27. $strMessage = "";
  28. $bolDone = false;
  29. $bolPassed = true;
  30. $dtNow = fnMySqlNow();
  31.  
  32. //app vars...
  33. $command = fnGetReqVal("command", "", $myRequestVars);
  34. $appGuid = fnGetReqVal("appGuid", "", $myRequestVars);
  35. $appName = fnGetReqVal("appName", "", $myRequestVars);
  36. $confirmCopyright = fnGetReqVal("confirmCopyright", "", $myRequestVars);
  37.  
  38. //cleans up project name
  39. function fnProjectName($theVal){
  40. $theVal = str_replace(" ", "", $theVal);
  41. $theVal = strtolower($theVal);
  42. return $theVal;
  43. }
  44.  
  45. //on submit
  46. if($isFormPost){
  47.  
  48. if(strlen($appName) < 3){
  49. $strMessage .= "<br/>Enter at least 3 characters for the app's name.";
  50. $bolPassed = false;
  51. }else{
  52. if(!fnIsAlphaNumeric($appName, true)){
  53. $strMessage .= "<br/>Letters and numbers only for app names.";
  54. $bolPassed = false;
  55. }
  56. }
  57.  
  58. //if good, title must start with a letter
  59. if($bolPassed){
  60. $nums = array("0","1","2","3","4","5","6","7","8","9");
  61. $firstChar = substr($appName, 0, 1);
  62. if(in_array($firstChar, $nums)){
  63. $strMessage .= "<br/>App names must begin with a letter.";
  64. $bolPassed = false;
  65. }
  66. }
  67.  
  68. if($confirmCopyright != "1"){
  69. $strMessage .= "<br/>Check the \"I understand the copyright laws\" checkbox.";
  70. $bolPassed = false;
  71. }
  72.  
  73. if($bolPassed){
  74. //check for dups
  75. $strSql = "SELECT id FROM " . TBL_APPLICATIONS . " WHERE status != 'deleted' AND name = '" . $appName . "'";
  76. $iDups = fnGetOneValue($strSql, APP_DB_HOST, APP_DB_NAME, APP_DB_USER, APP_DB_PASS);
  77. if($iDups != ""){
  78. $strMessage .= "<br/>Choose a different name for the app, the one you entered is already in use.";
  79. $bolPassed = false;
  80. }
  81. }
  82.  
  83. //applications directory must exist...
  84. if(!is_dir("../.." . APP_DATA_DIRECTORY . "/applications")){
  85. $strMessage .= "<br/>The Applications directory does not exist? Contact a system administrator for help.";
  86. $bolPassed = false;
  87. }else{
  88. if(!is_writeable("../.." . APP_DATA_DIRECTORY . "/applications")){
  89. $strMessage .= "<br/>The Applications directory is not writeable? Contact a system administrator for help.";
  90. $bolPassed = false;
  91. }
  92. }
  93.  
  94. //create app
  95. if($bolPassed){
  96.  
  97. //do dups
  98. if($appGuid == ""){
  99.  
  100. //new app
  101. $appGuid = "EA" . strtoupper(fnCreateGuid()); //guid's must begin with a letter.
  102.  
  103. //create an apiKey and secret...ALL APPS need an apiKey to request data....
  104. $newApiKey = strtoupper(fnCreateGuid());
  105. $newApiSecret = strtoupper(fnCreateGuid());
  106.  
  107. //create an app...
  108. $objApp = new App("");
  109. $objApp->infoArray['guid'] = $appGuid;
  110. $objApp->infoArray['ownerGuid'] = $guid;
  111. $objApp->infoArray['apiKey'] = $newApiKey;
  112. $objApp->infoArray['appSecret'] = $newApiSecret;
  113. $objApp->infoArray['version'] = "2.0";
  114. $objApp->infoArray['currentMode'] = "design";
  115. $objApp->infoArray['currentPublishVersion'] = "1.0";
  116. $objApp->infoArray['currentPublishDate'] = $dtNow;
  117. $objApp->infoArray['name'] = fnFormInput($appName);
  118. $objApp->infoArray['projectName'] = fnProjectName($appName);
  119. $objApp->infoArray['dataURL'] = APP_URL . "/api/app/?command=getAppData&appGuid=" . $appGuid . "&apiKey=" . $newApiKey . "&apiSecret=" . $newApiSecret;
  120. $objApp->infoArray['cloudURL'] = APP_URL . "/api/app/?command=reportToCloud&appGuid=" . $appGuid . "&apiKey=" . $newApiKey . "&apiSecret=" . $newApiSecret . "&deviceId=[deviceId]&deviceLatitude=[deviceLatitude]&deviceLongitude=[deviceLongitude]&deviceModel=[deviceModel]&userId=[userId]";
  121. $objApp->infoArray['registerForPushURL'] = APP_URL . "/api/app/?command=registerForPush&appGuid=" . $appGuid . "&apiKey=" . $newApiKey . "&apiSecret=" . $newApiSecret . "&deviceId=[deviceId]&deviceLatitude=[deviceLatitude]&deviceLongitude=[deviceLongitude]&deviceModel=[deviceModel]&userId=[userId]";
  122. $objApp->infoArray['dataDir'] = APP_DATA_DIRECTORY . "/applications/" . $appGuid;
  123. $objApp->infoArray['startGPS'] = "0";
  124. $objApp->infoArray['startAPN'] = "0";
  125. $objApp->infoArray['allowRotation'] = "largeDevicesOnly";
  126. $objApp->infoArray['iconUrl'] = "";
  127. $objApp->infoArray['iconName'] == "";
  128. $objApp->infoArray['viewCount'] = "0";
  129. $objApp->infoArray['deviceCount'] = "0";
  130. $objApp->infoArray['status'] = "created";
  131. $objApp->infoArray['modifiedUTC'] = $dtNow;
  132. $objApp->infoArray['dateStampUTC'] = $dtNow;
  133. $objApp->fnInsert();
  134.  
  135. //create an API key for this app...
  136. $objBtApiKey = new Bt_apikey("");
  137. $objBtApiKey->infoArray['guid'] = strtoupper(fnCreateGuid());
  138. $objBtApiKey->infoArray['apiKey'] = $newApiKey;
  139. $objBtApiKey->infoArray['apiSecret'] = md5($newApiSecret);
  140. $objBtApiKey->infoArray['ownerName'] = "App: " . fnFormInput($appName);
  141. $objBtApiKey->infoArray['email'] = "";
  142. $objBtApiKey->infoArray['allowedIPAddress'] = "";
  143. $objBtApiKey->infoArray['expiresDate'] = fnMySqlDate("01/01/2025");
  144. $objBtApiKey->infoArray['lastRequestUTC'] = "";
  145. $objBtApiKey->infoArray['requestCount'] = "0";
  146. $objBtApiKey->infoArray['dateStampUTC'] = $dtNow;
  147. $objBtApiKey->infoArray['modifiedUTC'] = $dtNow;
  148. $objBtApiKey->infoArray['status'] = "active";
  149. $objBtApiKey->fnInsert();
  150.  
  151. //create a default app user for the owner...
  152. $objAppUser = new Appuser();
  153. $objAppUser -> infoArray["guid"] = strtoupper(fnCreateGuid());
  154. $objAppUser -> infoArray["appGuid"] = fnFormInput($appGuid);
  155. $objAppUser -> infoArray["userType"] = "owner";
  156. $objAppUser -> infoArray["displayName"] = $thisUser->infoArray["firstName"] . " " . $thisUser->infoArray["lastName"];
  157. $objAppUser -> infoArray["email"] = strtolower($thisUser->infoArray["email"]);
  158. $objAppUser -> infoArray["encLogInPassword"] = md5($thisUser->infoArray["logInPassword"]);
  159. $objAppUser -> infoArray["status"] = "active";
  160. $objAppUser -> infoArray["numRequests"] = "0";
  161. $objAppUser -> infoArray["lastRequestUTC"] = '';
  162. $objAppUser -> infoArray["lastLoginUTC"] = '';
  163. $objAppUser -> infoArray["dateStampUTC"] = $dtNow;
  164. $objAppUser -> infoArray["modifiedUTC"] = $dtNow;
  165. $objAppUser -> fnInsert();
  166.  
  167. //create a default theme...
  168. $newThemeGuid = strtoupper(fnCreateGuid());
  169. $objTheme = new Bt_item();
  170. $objTheme -> infoArray["guid"] = $newThemeGuid;
  171. $objTheme -> infoArray["parentItemGuid"] = "";
  172. $objTheme -> infoArray["uniquePluginId"] = "";
  173. $objTheme -> infoArray["loadClassOrActionName"] = "";
  174. $objTheme -> infoArray["hasChildItems"] = "0";
  175. $objTheme -> infoArray["loadItemGuid"] = "";
  176. $objTheme -> infoArray["appGuid"] = fnFormInput($appGuid);
  177. $objTheme -> infoArray["controlPanelItemType"] = "theme";
  178. $objTheme -> infoArray["itemType"] = "BT_theme";
  179. $objTheme -> infoArray["itemTypeLabel"] = "Global Theme";
  180. $objTheme -> infoArray["nickname"] = "Default Theme";
  181. $objTheme -> infoArray["orderIndex"] = "0";
  182. $objTheme -> infoArray["jsonVars"] = "{\"itemId\":\"" . $newThemeGuid . "\", \"itemType\":\"BT_theme\", \"backgroundColor\":\"#FFFFFF\"}";
  183. $objTheme -> infoArray["status"] = "active";
  184. $objTheme -> infoArray["dateStampUTC"] = $dtNow;
  185. $objTheme -> infoArray["modifiedUTC"] = $dtNow;
  186. $objTheme -> fnInsert();
  187.  
  188. //every app needs a writeable directory for files and other assets. This is created on the app's home-screen.
  189. //this approach allows us to make sure it's directory exists everytime the app's control panel is loaded.
  190.  
  191. //flag as done.
  192. $bolDone = true;
  193.  
  194.  
  195. }else{
  196. //flag
  197. $bolDone = true;
  198. }
  199.  
  200. }//if passed
  201.  
  202.  
  203. }else{
  204.  
  205.  
  206. }//not posted
  207.  
  208.  
  209. //print html...
  210. echo $thisPage->fnGetPageHeaders();
  211. echo $thisPage->fnGetBodyStart();
  212. echo $thisPage->fnGetTopNavBar($thisUser->infoArray['guid']);
  213.  
  214. ?>
  215.  
  216. <?php if($bolDone){ ?>
  217. <script type="text/javascript">
  218. function doneBuilding(){
  219. document.getElementById("isLoading").style.display = "none";
  220. document.getElementById("doneLoading").style.display = "block";
  221. }
  222. window.setTimeout(doneBuilding, 7000, true);
  223. </script>
  224. <?php } ?>
  225.  
  226.  
  227.  
  228. <input type="hidden" name="appGuid" id="appGuid" value="<?php echo $appGuid;?>">
  229. <input type="hidden" name="command" id="command" value="<?php echo $command;?>">
  230.  
  231.  
  232.  
  233. <div class='content'>
  234. <div class='content'>
  235.  
  236. <fieldset class='colorLightBg'>
  237.  
  238. <!-- left side-->
  239. <div class='boxLeft'>
  240. <div class='contentBox colorDarkBg minHeight'>
  241. <div class='contentBand colorBandBg'>
  242. <?php echo fnFormOutput($userName);?>
  243. </div>
  244. <div id="leftNavLinkBox" style='padding:10px;white-space:nowrap;'>
  245.  
  246. <?php if(strtoupper($thisUser->infoArray["userType"]) == "ADMIN"){ ?>
  247. <div><a href="<?php echo fnGetSecureURL(APP_URL);?>/admin/" title="Admin Home"><img src="../../images/arr_right.gif">Admin Home</a></div>
  248. <?php } ?>
  249.  
  250.  
  251. <?php echo $thisPage->fnGetControlPanelLinks("account", "", "block", ""); ?>
  252.  
  253. </div>
  254. </div>
  255. </div>
  256.  
  257. <!-- right side-->
  258. <div class='boxRight'>
  259. <div class='contentBox colorLightBg minHeight'>
  260. <div class='contentBand colorBandBg'>
  261. Create a New Application
  262. </div>
  263.  
  264. <div style='padding:10px;'>
  265.  
  266. <?php if(!$bolDone && $strMessage != ""){ ?>
  267. <div class='errorDiv'>
  268. <?php echo $strMessage; ?>
  269. </div>
  270. <?php } ?>
  271.  
  272.  
  273.  
  274. <?php if($bolDone){ ?>
  275.  
  276. <div id="isLoading" class="cpExpandoBox" style="padding:25px;height:250px;text-align:center;display:block;margin-right:auto;margin-left:auto;">
  277. <div style='font-size:150%;color:#666666;'>Building "<?php echo fnFormOutput($appName);?>"</div>
  278. <img src="<?php echo fnGetSecureURL(APP_URL);?>/images/gif-loading.gif">
  279. <br/>
  280. <br/>
  281. </div>
  282.  
  283. <div id="doneLoading" style="display:none;">
  284. <div class='doneDiv'>
  285. <b>"<?php echo fnFormOutput($appName);?>" Created Successfully</b>
  286. </div>
  287.  
  288. <div class='infoDiv'>
  289. <b>Next steps...</b>
  290. <ol>
  291. <li>Visit the apps control panel and upload an icon.</li>
  292. <li>Download the source code for the application and launch it in the simulator.</li>
  293. <li>Add screens and menu's to the application using the control panel.</li>
  294. </ol>
  295. <div>
  296. <a href="index.php?appGuid=<?php echo $appGuid;?>" title="app control panel"><img src="<?php echo fnGetSecureURL(APP_URL);?>/images/arr_right.gif" alt="arrow"/>Continue to this app's control panel</a>
  297. </div>
  298. </div>
  299. </div>
  300.  
  301.  
  302. <?php } ?>
  303.  
  304. <?php if(!$bolDone){ ?>
  305.  
  306. <b>Name the App</b> (letters and numbers only)<br/>
  307. <input type="text" value="<?php echo fnFormOutput($appName)?>" name="appName" id="appName" maxlength='50' />
  308. <br/>App names must begin with a letter.
  309.  
  310. <div style='padding-top:10px;padding-left:5px;'>
  311. <input type="checkbox" name="confirmCopyright" id="confirmCopyright" value="1" <?php echo fnGetChecked($confirmCopyright, "1");?> />
  312. I understand these
  313. <a href="http://www.copyright.gov/" target="_blank"/>copyright laws</a>
  314. </div>
  315.  
  316. <div style='padding:5px;padding-top:10px;'>
  317. <input type="button" id="btnSubmit" value="save" class="buttonSubmit" onclick="document.forms[0].submit();"/>
  318. <input type="button" class="buttonCancel" value="cancel" onclick="document.location.href='<?php echo $cancelURL;?>';">
  319. </div>
  320.  
  321. <?php } ?>
  322.  
  323.  
  324.  
  325.  
  326. </div>
  327. </div>
  328. </div>
  329.  
  330. </fieldset>
  331.  
  332.  
  333. <?php echo $thisPage->fnGetBottomNavBar();?>
  334. </div>
  335. <?php echo $thisPage->fnGetBodyEnd(); ?>
Advertisement
Add Comment
Please, Sign In to add comment