/** Define any javascript needed @return A javascript string function javascript_content(){ } */ function body_content() { include '../config.php'; ob_start(); ?> <?php echo showInstallTabs('Menu'); ?> <form action=InstallMenuPage.php method=post> <h1 class="install"> <?php if (!$this->themed) { echo "<h1 class='install'>{$this->header}</h1>"; } ?> </h1> <?php if (is_writable('../config.php')) { echo "<div class=\"alert alert-success\"><i>config.php</i> is writeable</div>"; } else { echo "<div class=\"alert alert-danger\"><b>Error</b>: config.php is not writeable</div>"; echo "<br />Full path is: " . '../config.php' . "<br />"; if (function_exists('posix_getpwuid')) { $chk = posix_getpwuid(posix_getuid()); echo "PHP is running as: " . $chk['name'] . "<br />"; } else { echo "PHP is (probably) running as: " . get_current_user() . "<br />"; } } ?> <hr /> <p class="ichunk"> Whether to always show the Fannie Administration Menu. <ul> <li>Coops may prefer not to show the menu in order to maximize the space available on the page for the report or tool. <li>Some pages may show or not show the Fannie Menu regardless of this setting, but setting it to Yes will increase the number of pages on which the menu appears. </ul> <b>Show Admin menu</b> <!-- "windowdressing" is the term used in Class Lib 2.0 for the heading and navigation menu. Use this to set the value of $window_dressing. --> <?php echo installSelectField('FANNIE_WINDOW_DRESSING', $FANNIE_WINDOW_DRESSING, array(1 => 'Yes', 0 => 'No'), false); ?> </p> <hr /> <p class="ichunk"> Use this tool to customize Fannie's menu. Usage: <ul> <li>Left hand text box contains the menu entry text <li>Right hand box contains a URL or a special value for other types of entries such as section headers. <li>URLs are relative to Fannie <i>unless</i> they begin with / or a protocol (http://, https://, etc). </ul> <h4 class="install">Fannie Menu Builder</h4> <?php $VALID_MENUS = array('Item Maintenance', 'Sales Batches', 'Reports', 'Membership', 'Synchronize', 'Admin', '__store__'); if (!isset($FANNIE_MENU) || !is_array($FANNIE_MENU)) { include '../src/init_menu.php'; $FANNIE_MENU = $INIT_MENU; } else { foreach ($FANNIE_MENU as $menu => $content) { if (!in_array($menu, $VALID_MENUS)) { // menu is not valid // reset to default // obviously not ideal error recovery include '../src/init_menu.php'; $FANNIE_MENU = $INIT_MENU; break; } } } for ($i = 0; $i < count($VALID_MENUS); $i++) { $post_titles = FormLib::get('m_title' . $i); $post_urls = FormLib::get('m_url' . $i); if (!is_array($post_titles) || !is_array($post_urls)) { continue; } /** rebuild from posted data **/ $FANNIE_MENU[$VALID_MENUS[$i]] = array(); $divider_count = 1; for ($j = 0; $j < count($post_titles); $j++) { $p_title = $post_titles[$j]; $p_url = $post_urls[$j]; // url must have some kind of value // title may be empty on dividers if (empty($p_url)) { continue; } if ($p_url == '__divider__') { $p_title = 'divider' . $divider_count; $divider_count++; } elseif (empty($p_title)) { continue; } $FANNIE_MENU[$VALID_MENUS[$i]][$p_title] = $p_url; } } if (FormLib::get('import-menu') !== '') { $import = FormLib::get('import-menu'); $json = json_decode($import, true); if ($json === null) { echo '<div class="alert alert-danger">Menu Import is not valid JSON</div>'; } else { $valid = true; foreach ($json as $menu => $content) { if (!in_array($menu, $VALID_MENUS)) { echo '<div class="alert alert-danger"><strong>' . $menu . '</strong> is not a valid top-level menu</div>'; $valid = false; break; } elseif (!is_array($content)) { echo '<div class="alert alert-danger">Entries for <strong>' . $menu . '</strong> are not valid. It should be a JSON object with keys representing menu titles and values represeting URLs or the special values __header__ and __divider__</div>'; $valid = false; break; } } if ($valid) { $FANNIE_MENU = $json; echo '<div class="alert alert-success">Imported menu</div>'; } } } $saveStr = 'array('; $menu_number = 0; $select = '<select onchange="$(this).next(\'input\').val($(this).val());" class="form-control"> <option value="">URL</option>'; $opts = array('__header__' => 'Section Header', '__divider__' => 'Divider Line'); foreach ($FANNIE_MENU as $menu => $content) { $saveStr .= "'" . $menu . "' => array("; echo '<b>' . $menu . '</b>'; echo '<ul id="menuset' . $menu_number . '">'; foreach ($content as $m_title => $m_url) { $saveStr .= "'" . str_replace("'", "\\'", $m_title) . "' => '" . $m_url . "',"; echo '<li class="form-inline">'; printf('<input type="text" name="m_title%d[]" value="%s" class="form-control" />', $menu_number, $m_title); echo $select; foreach ($opts as $key => $val) { printf('<option %s value="%s">%s</option>', $key == $m_url ? 'selected' : '', $key, $val); } echo '</select>'; printf('<input type="text" name="m_url%d[]" value="%s" class="form-control" />', $menu_number, $m_url); echo ' [ <a href="" onclick="$(this).parent().remove(); return false;">Remove Entry</a> ]'; echo '</li>'; } $saveStr .= '),'; echo '</ul>'; $newEntry = sprintf('<li class="form-inline"> <input type="text" name="m_title%d[]" value="" class="form-control" />%s', $menu_number, $select); foreach ($opts as $key => $val) { $newEntry .= sprintf('<option value="%s">%s</option>', $key, $val); } $newEntry .= sprintf('</select><input type="text" name="m_url%d[]" value="" class="form-control" /> [ <a href="" onclick="$(this).parent().remove(); return false;">Remove Entry</a> ] </li>', $menu_number); echo '<div id="newEntry' . $menu_number . '" class="collapse">'; echo $newEntry; echo '</div>'; printf('[ <a href="" onclick="$(\'ul#menuset%d\').append($(\'#newEntry%d\').html()); return false;">Add New Entry</a> to %s ]', $menu_number, $menu_number, $menu); echo '<br />'; $menu_number++; } $saveStr .= ')'; confset('FANNIE_MENU', $saveStr); ?> <hr /> <div class="form-group"> <label>Hand-editable Menu / Export</label> <textarea class="form-control" rows="15"> <?php echo \COREPOS\Fannie\API\lib\FannieUI::prettyJSON(json_encode($FANNIE_MENU)); ?> </textarea> </div> <div class="form-group"> <label>Import Menu (use same JSON format)</label> <textarea name="import-menu" class="form-control" rows="15"></textarea> </div> <p> <button type="submit" name="psubmit" value="1" class="btn btn-default">Save Configuration</button> </p> </form> </body> </html> <?php return ob_get_clean(); // body_content }
public function body_content() { include dirname(__FILE__) . '/../config.php'; ob_start(); echo showInstallTabs('Stores'); ?> <form action=InstallStoresPage.php method=post> <h1 class="install"> <?php if (!$this->themed) { echo "<h1 class='install'>{$this->header}</h1>"; } ?> </h1> <p class="ichunk">Revised 23Apr2014</p> <?php if (is_writable('../config.php')) { echo "<div class=\"alert alert-success\"><i>config.php</i> is writeable</div>"; } else { echo "<div class=\"alert alert-danger\"><b>Error</b>: config.php is not writeable</div>"; } ?> <hr /> <h4 class="install">Stores</h4> <p class="ichunk" style="margin:0.0em 0em 0.4em 0em;"> <?php $model = new StoresModel(FannieDB::get($FANNIE_OP_DB)); $model->dbHost($FANNIE_SERVER); $myself = $model->find(); if (count($myself) == 0) { echo '<i>No entry found for this store. Adding one automatically...</i><br />'; $model->description('CURRENT STORE'); $model->save(); } else { if (count($myself) > 1) { echo '<i>Warning: more than one entry for store host: ' . $FANNIE_SERVER . '</i><br />'; } else { echo '<i>This store is #' . installTextField('FANNIE_STORE_ID', $FANNIE_STORE_ID, $myself[0]->storeID()) . '</i><br />'; } } $model->reset(); echo '<label>Mode</label>'; echo installSelectField('FANNIE_STORE_MODE', $FANNIE_STORE_MODE, array('STORE' => 'Single Store', 'HQ' => 'HQ'), 'STORE'); $supportedTypes = array('none' => ''); if (extension_loaded('pdo') && extension_loaded('pdo_mysql')) { $supportedTypes['PDO_MYSQL'] = 'PDO MySQL'; } if (extension_loaded('mysqli')) { $supportedTypes['MYSQLI'] = 'MySQLi'; } if (extension_loaded('mysql')) { $supportedTypes['MYSQL'] = 'MySQL'; } if (extension_loaded('mssql')) { $supportedTypes['MSSQL'] = 'MSSQL'; } ?> <table class="table"> <tr> <th>Store #</th><th>Description</th><th>DB Host</th> <th>Driver</th><th>Username</th><th>Password</th> <th>Operational DB</th> <th>Transaction DB</th> <th>Push</th> <th>Pull</th> <th>Own Items</th> <th>Delete Entry</th> </tr> <?php foreach ($model->find('storeID') as $store) { printf('<tr %s> <td>%d<input type="hidden" name="storeID[]" value="%d" /></td> <td><input type="text" class="form-control" name="storeName[]" value="%s" /></td> <td><input type="text" class="form-control" name="storeHost[]" value="%s" /></td>', $store->dbHost() == $FANNIE_SERVER ? 'class="info"' : '', $store->storeID(), $store->storeID(), $store->description(), $store->dbHost()); echo '<td><select name="storeDriver[]" class="form-control">'; foreach ($supportedTypes as $key => $label) { printf('<option %s value="%s">%s</option>', $store->dbDriver() == $key ? 'selected' : '', $key, $label); } echo '</select></td>'; printf('<td><input type="text" class="form-control" name="storeUser[]" value="%s" /></td> <td><input type="password" class="form-control" name="storePass[]" value="%s" /></td> <td><input type="text" class="form-control" name="storeOp[]" value="%s" /></td> <td><input type="text" class="form-control" name="storeTrans[]" value="%s" /></td> <td><input type="checkbox" name="storePush[]" value="%d" %s /></td> <td><input type="checkbox" name="storePull[]" value="%d" %s /></td> <td><input type="checkbox" name="storeItems[]" value="%d" %s /></td> <td><input type="checkbox" name="storeDelete[]" value="%d" /></td> </tr>', $store->dbUser(), $store->dbPassword(), $store->opDB(), $store->transDB(), $store->storeID(), $store->push() ? 'checked' : '', $store->storeID(), $store->pull() ? 'checked' : '', $store->storeID(), $store->hasOwnItems() ? 'checked' : '', $store->storeID()); } ?> </table> </p> <hr /> <h4 class="install">Testing Connections</h4> <p class="ichunk" style="margin:0.0em 0em 0.4em 0em;"> <ul> <?php foreach ($model->find('storeID') as $store) { $test = db_test_connect($store->dbHost(), $store->dbDriver(), $store->transDB(), $store->dbUser(), $store->dbPassword()); echo '<li> Store #' . $store->storeID() . ': ' . ($test ? 'Connected' : 'No connection') . '</li>'; } ?> </ul> <i>Note: it's OK if this store's connection fails as long as it succeeds on the "Necessities" tab.</i> </p> <hr /> <h4 class="install">Read-only Database Server(s)</h4> <p class="ichunk" style="margin:0.0em 0em 0.4em 0em;"> Specify one or more database servers that can be used strictly for read operations. If more than one database is listed, read-only queries will be load-balanced across them. <?php if (!isset($FANNIE_READONLY_JSON)) { $FANNIE_READONLY_JSON = json_encode(array(array('host' => $FANNIE_SERVER, 'type' => $FANNIE_SERVER_DBMS, 'user' => $FANNIE_SERVER_USER, 'pw' => $FANNIE_SERVER_PW))); } confset('FANNIE_READONLY_JSON', "'{$FANNIE_READONLY_JSON}'"); ?> <textarea rows="10" cols="30" name="FANNIE_READONLY_JSON" class="form-control"> <?php echo \COREPOS\Fannie\API\lib\FannieUI::prettyJSON($FANNIE_READONLY_JSON); ?> </textarea> <hr /> <p> <button type=submit name="saveButton" value="Save" class="btn btn-default">Save</button> <button type=submit name="addButton" value="Add Another Store" class="btn btn-default">Add Another Store</button> </p> </form> <?php return ob_get_clean(); // body_content }