ITS381B Database local and remote

Campus Project has remote access to server db and its step-by-step vid by Dr. Halberson.

https://secrdir.com/campus/ionic/ionic.php

The key website is below with all the php codes.

https://secrdir.com/campus/ionic/ionic_2_pro.php

Adding Page Controller JavaScript

important website is https://secrdir.com/campus/ionic/ionic_2_pro.php

yellow sections has Add Agent and service programs. If executed, all the information is send to Server to update database. If you enter the url and all the values followed by typing you will be able to send those data to server to enter db.

EG:

If you execute Execute add agent on the webpage by adding “?…” as the following:

https://secrdir.com/campus/ionic/add_agent.php?AgentName=Joe schmoe&OfficeKey=5”

https://secrdir.com/campus/ionic/add_agent.php?AgentName=Joe%20Schmoe&OfficeKey=5

You will receive the screen of the following is returned. So this php is returned where it was called of the JavaScript section and displays on the client screen(?) by confirming what was added.

{ “datetime”: “2018-10-22 19:04:06”, “inserted”: 1, “message”: “Joe Schmoe added at Puna location.”, “AgentID”: “15”, “AgentName”: “Joe Schmoe”, “OfficeKey”: “5”, “OfficeLocation”: “Puna” }

The screen shot is as below.

  • Add Agent
    Replace line: function ($scope, $stateParams) {
    with 25 lines of code:

    function ($scope, $stateParams, GetOffices, AddAgent) {
    
      $scope.offices = [];    
    
      $scope.data = {};
    
      $scope.addAgent = function(){
        var agent = $scope.data.agent;
        var office = $scope.data.office;
        $scope.hideButton=true;
    
        AddAgent.getPost(agent, office) 
        .then(function(response) {
          $scope.post = response;
         });
      };
    
      GetOffices.getPost()
      .then(function(response) {
        $scope.post = response;
        $scope.offices =  $scope.post.records;
    	$scope.offices.unshift({ "OfficeID": 0, "OfficeLocation": "--- Select Office Location ---" });
    	$scope.data.office=0;
      });
    

 

Adding API Services JavaScript

and look for services. Sending to server using POST request.

url + ? + agend + are etc. using Execute you will understand.

9. In the left Code panel, scroll down to Other JS. Click to open the services.js code.

The first line of services.js should be: angular.module('app.services', [])

Just after the first line, insert the following 212 lines of code:

.service('GetAgentBookings', function($http) {
  return {
    getPost: function() {
      var columns="AgentName, OfficeLocation, SUM(1) AS NumSales, SUM(IF(Amount IS NOT NULL,Amount,0)) AS Total";
      var table=encodeURIComponent("AGENT LEFT JOIN SALE ON AgentKey=AgentID LEFT JOIN OFFICE ON OfficeKey=OfficeID");
      var group="AgentID";
      var order="Total DESC";
      var query = '?columns='+columns;
      query += '&table='+table;
      query += '&group='+group;
      query += '&order='+order;

      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('GetSales', function($http) {
  return {
    getPost: function() {
      var columns = "SaleID, SaleDate, UNIX_TIMESTAMP(SaleDate)*1000 AS SaleTime, AgentKey, Amount, DestinationKey";
	  columns += ", AgentName, OfficeKey, OfficeLocation, DestinationName";
	  var tab = "SALE INNER JOIN AGENT ON AgentKey=AgentID INNER JOIN OFFICE ON OfficeKey=OfficeID ";
	  tab += " INNER JOIN DESTINATION ON DestinationKey=DestinationID";
      var table = encodeURIComponent(tab);
      var order="SaleID DESC";

      var query = '?columns='+columns;
      query += '&table='+table;
      query += '&order='+order;

      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('GetOffices', function($http) {
  return {
    getPost: function() {

      var query = '?table=OFFICE&order=OfficeLocation';

      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('GetAgents', function($http) {
  return {
    getPost: function() {

      var query = '?table=AGENT&order=AgentName';

      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('GetDestinations', function($http) {
  return {
    getPost: function() {

      var query = '?table=DESTINATION&order=DestinationName';

      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('AddAgent', function($http) {
  return {
    getPost: function(agent,office) {
      var query = '?AgentName='+agent;
      query += '&OfficeKey='+office;
      return $http.get('https://secrdir.com/campus/ionic/add_agent.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('AddSale', function($http) {
  return {
    getPost: function(agent,saleDate,amount,destination) {
      var query = '?AgentKey='+agent;
      query += '&DestinationKey='+destination;
      query += '&Amount='+amount;
      query += '&SaleDate='+saleDate;
      return $http.get('https://secrdir.com/campus/ionic/add_sale.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('SearchSales', function($http) {
  return {
    getPost: function(agent, destination, amountsAbove, amountsBelow) {
      var columns = "SaleID, SaleDate, UNIX_TIMESTAMP(SaleDate)*1000 AS SaleTime, AgentKey, Amount, DestinationKey";
	  columns += ", AgentName, OfficeKey, OfficeLocation, DestinationName";
	  var tab = "SALE INNER JOIN AGENT ON AgentKey=AgentID INNER JOIN OFFICE ON OfficeKey=OfficeID ";
	  tab += " INNER JOIN DESTINATION ON DestinationKey=DestinationID";
      var table = encodeURIComponent(tab);
      var order="SaleID DESC";
      var query = '?columns='+columns;
      query += '&table='+table;
      query += '&order='+order;

	  var where = "";
	  if(agent > 0 ) { where += " AND AgentKey="+agent ; }
	  if(destination > 0 ) { where += " AND DestinationKey="+destination ; }
	  if(amountsAbove > 0 ) { where += " AND Amount>='"+amountsAbove+"'" ; }
	  if(amountsBelow > 0 ) { where += " AND Amount<='"+amountsBelow+"'" ; }
	  if(where>'') {
		  where = where.substr(4) ;
		  where=encodeURIComponent(where);
		  query += '&where='+where ;
      }
      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})

.service('GetSale', function($http) {
  return {
    getPost: function(saleId) {
      var columns = "SaleID, SaleDate, UNIX_TIMESTAMP(SaleDate)*1000 AS SaleTime, AgentKey, Amount, DestinationKey";
	  columns += ", AgentName, OfficeKey, OfficeLocation, DestinationName";
	  var tab = "SALE INNER JOIN AGENT ON AgentKey=AgentID INNER JOIN OFFICE ON OfficeKey=OfficeID ";
	  tab += " INNER JOIN DESTINATION ON DestinationKey=DestinationID";
      var table = encodeURIComponent(tab);

      var query = '?columns='+columns;
      query += '&table='+table;
      query += '&where='+encodeURIComponent("SaleID=" + saleId);

      return $http.get('https://secrdir.com/campus/ionic/list.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})


.service('DeleteSale', function($http) {
  return {
    getPost: function(saleId, originalAgent, originalSaleDate, originalAmount, originalDestination) {
      var query = '?SaleID='+saleId;
      query += '&Original_AgentKey='+originalAgent;
      query += '&Original_DestinationKey='+originalDestination;
      query += '&Original_Amount='+originalAmount;
      query += '&Original_SaleDate='+originalSaleDate;

	  return $http.get('https://secrdir.com/campus/ionic/delete_sale.php'+query)
      .then(function (response) {
        return response.data;
      });
    }
  };
})


.service('UpdateSale', function($http) {
  return {
    getPost: function(saleId, originalAgent, originalSaleDate, originalAmount, originalDestination, 
		agent, saleDate, amount, destination) {
      var query = '?SaleID='+saleId;
      query += '&Original_AgentKey='+originalAgent;
      query += '&Original_DestinationKey='+originalDestination;
      query += '&Original_Amount='+originalAmount;
      query += '&Original_SaleDate='+originalSaleDate;
	  var changes = 0;
      if(agent != originalAgent) { query += '&AgentKey='+agent; changes += 1; }
      if(destination != originalDestination) { query += '&DestinationKey='+destination; changes += 1; }
      if(amount != originalAmount) { query += '&Amount='+amount; changes += 1; }
      if(saleDate != originalSaleDate) { query += '&SaleDate='+saleDate; changes += 1; }
	  if( changes == 0 )
      {
        var message = { "message" : "Nothing to update" };
        return message;
      }
      else
      {
		  return $http.get('https://secrdir.com/campus/ionic/update_sale.php'+query)
		  .then(function (response) {
			return response.data;
		  });
	  }
    }
  };
})

 

 

 

https://secrdir.com/campus/ionic/files.php?show=add_agent.php

Check Execution to see json

https://secrdir.com/campus/ionic/add_agent.php?AgentName=Joe%20Schmoe&OfficeKey=5

 

 

ngCordova upload photo