array( 'status' => 0, 'data' => $_SESSION['books'] ) ); // Encode $response in json format echo json_encode( $response ); } // add-json action else if ( $act == 'add-json' ) { if ( is_array( $_SESSION['books'] ) ) { // Get last position + 1 on array and set $id with the key end( $_SESSION['books'] ); $id = key( $_SESSION['books'] ) + 1; } else { $id = 1; } // Set array with data that user posted $newArray = array( 'id' => $id, 'name' => $_POST['name'] ); // Add the new array to the session var $_SESSION['books'][ $id ] = $newArray; // Set $response var $response = array( 'response' => array( 'status' => 0, 'data' => $newArray ) ); // Encode $response in json format echo json_encode( $response ); } // edit-json action else if ( $act == 'edit-json' ) { // Update session var $_SESSION['books'][ $_POST['id'] ] = $_POST['name']; // Set $response var $response = array( 'response' => array( 'status' => 0 ) ); // Encode $response in json format echo json_encode( $response ); } // delete-json action else if ( $act == 'delete-json' ) { // Remove book from session var unset( $_SESSION['books'][ $_POST['id'] ] ); // Set $response var $response = array( 'response' => array( 'status' => 0 ) ); // Encode $response in json format echo json_encode( $response ); } // add action else if ( $act == 'add' ) { // Instance ScForm() $scForm = new ScForm(); // Add header to this form $scForm->addHeader( 'General Information' ); // Add name field $options = array( 'required' => true, 'width' => '50%' ); $scForm->addTextField( 'name' , 'Name' , null , $options ); // Create form echo $scForm->create( 'booksAddForm' , null , array( 'width' => '100%', 'dataSource' => 'booksDS', 'canSubmit' => false, 'showErrorText' => true, 'errorOrientation' => 'right', 'numCols' => 2, 'colWidths' => $scForm->addQuotesStr( '[120, \'*\']' ) ) ); // Save button $saveButton = new ScButton(); $options = array( 'icon' => '../images/accept.png', 'width' => 100, 'top' => 60, 'left' => 120 ); $js = "function() { saveAddForm( booksAddForm , booksLayout ); }"; echo $saveButton->create( 'Save' , $js , 'IButton' , $options ); // Cancel button $cancelButton = new ScButton(); $options = array( 'icon' => '../images/cancel.png', 'width' => 100, 'top' => 60, 'left' => 230 ); $js = "function() { cancelAddForm( booksLayout ); }"; echo $cancelButton->create( 'Cancel' , $js , 'IButton' , $options ); } // edit action else if ( $act == 'edit' ) { // Instance ScForm() $scForm = new ScForm(); // Add header to this form $scForm->addHeader( 'General Information' ); $options = array( 'required' => true, 'width' => '50%' ); $scForm->addTextField( 'name' , 'Name' , null , $options ); echo $scForm->create( 'booksEditForm' , null , array( 'width' => '100%', 'dataSource' => 'booksDS', 'canSubmit' => false, 'showErrorText' => true, 'errorOrientation' => 'right', 'numCols' => 2, 'colWidths' => $scForm->addQuotesStr( '[120, \'*\']' ) ) ); // Save button $saveButton = new ScButton(); $options = array( 'icon' => '../images/accept.png', 'width' => 100, 'top' => 60, 'left' => 120 ); $js = "function() { saveEditForm( booksEditForm , booksLayout ); }"; echo $saveButton->create( 'Save' , $js , 'IButton' , $options ); // Cancel button $cancelButton = new ScButton(); $options = array( 'icon' => '../images/cancel.png', 'width' => 100, 'top' => 60, 'left' => 230 ); $js = "function() { cancelEditForm( booksLayout ); }"; echo $cancelButton->create( 'Cancel' , $js , 'IButton' , $options ); } // List action else if ( $act == 'list' ) { // Create add button $addButton = new ScButton(); $options = array( 'icon' => '../images/add.png', 'width' => 100, 'left' => 10, 'top' => 8 ); $js = 'function() { showAddForm( booksLayout ); }'; echo $addButton->create( 'Add' , $js , 'IButton' , $options ); // Create edit button $editButton = new ScButton(); $options = array( 'icon' => '../images/pencil.png', 'width' => 100, 'left' => 120, 'top' => 8 ); $js = "function() { showEditForm( booksGrid , booksLayout , booksEditForm ) }"; echo $editButton->create( 'Edit' , $js , 'IButton' , $options ); // Create delete button $deleteButton = new ScButton(); $options = array( 'icon' => '../images/delete.png', 'width' => 100, 'left' => 230, 'top' => 8 ); $js = 'function() { deleteData( booksGrid ); }'; echo $deleteButton->create( 'Delete' , $js , 'IButton' , $options ); // Create Grid $scGrid = new ScGrid(); $options = array( 'showFilterEditor' => true, 'canEdit' => false, 'top' => 40 ); echo $scGrid->create( 'booksGrid' , 'booksDS' , '100%' , '80%' , $options ); } // Window Action else { // Create a dataSource for this module $scDataSource = new ScDataSource(); $scDataSource->addField( 'id' , 'Id' , true , null , null , false ); $scDataSource->addField( 'name' , 'Name' ); echo $scDataSource->create( 'booksDS' , 'index.php?page=books&act=list-json' , 'index.php?page=books&act=add-json' , 'index.php?page=books&act=edit-json' , 'index.php?page=books&act=delete-json' ); // Instance and Add HTMLFlows for this module $scHtmlFlow = new ScHtmlFlow(); // List Action ( default ) echo $scHtmlFlow->create( 'booksList' , null , 'index.php?page=books&act=list' ); // Add Action echo $scHtmlFlow->create( 'booksAdd' , null , 'index.php?page=books&act=add' ); // Edit Action echo $scHtmlFlow->create( 'booksEdit' , null , 'index.php?page=books&act=edit' ); ?>