Files
ayanova7/archive/ayanova 1.9.4 CE final release db schema 171/sp/spView.cpp

909 lines
25 KiB
C++
Raw Blame History

// spView.cpp : implementation of the CSpView class
//
#include "stdafx.h"
#include "sp.h"
#include "spDoc.h"
#include "spView.h"
#include "UsersDlg.h"
#include "mailreaderdlg.h"
#include "LoginDlg.h"
#include "kd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//memory leak debugging help
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
//#define PRERELEASE 1 //<--to show build number
#define BUILD "supersecret"
#define LICENSE_SINGLESITE 0x0001
#define LICENSE_MULTISITE 0x0002
#define LICENSE_OTHERSITE1 0x0004
#define LICENSE_OTHERSITE2 0x0008
#define LICENSE_STANDARDEVAL 0x0010
#define LICENSE_REGISTERED 0x0020
#define LICENSE_TIMELIMITEDEVAL 0x0040
#define LICENSE_METEREDEVAL 0x0080
#define LICENSE_FEATUREH 0x0100
#define LICENSE_FEATUREI 0x0200
#define LICENSE_FEATUREJ 0x0400
#define LICENSE_FEATUREK 0x0800
#define LICENSE_FEATUREL 0x1000
#define LICENSE_FEATUREM 0x2000
/////////////////////////////////////////////////////////////////////////////
// CSpView
IMPLEMENT_DYNCREATE(CSpView, CFormView)
BEGIN_MESSAGE_MAP(CSpView, CFormView)
//{{AFX_MSG_MAP(CSpView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSpView construction/destruction
CSpView::CSpView()
: CFormView(CSpView::IDD)
{
//{{AFX_DATA_INIT(CSpView)
//}}AFX_DATA_INIT
// TODO: add construction code here
m_pApp = (CSpApp*)AfxGetApp();
cryp=new GZK;
//Initialize recordset pointer
rs=m_pApp->rsPool->GetRS("CSpView");
//cryp=NULL;
}
CSpView::~CSpView()
{
if(cryp!=NULL) delete cryp;
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
}
void CSpView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSpView)
//}}AFX_DATA_MAP
}
BOOL CSpView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
//Get some defaults
void CSpView::OnInitialUpdate()
{
CString q;
CWaitCursor wait;
//ShowWindow(SW_HIDE);
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//ShowWindow(SW_HIDE);
//CLoginDlg d;
//d.DoModal();
if(GetDocument()->LocateData()==false)
PostMessage(WM_QUIT);
//**********************************
// THIS was THE VERY FIRST DATABASE CALL:
q.Format("%s",cryp->InLineDecrypt("ASBscFrPeDOdk63cGRQwSVwgfPwTW0us6jTVaZsfmxydRtOj3AluIN+W3gAV4sey"));
//"SELECT defaults.* FROM defaults;"
rs->QueryReadOnly(q);
q.Format("%s",cryp->InLineDecrypt("UkE2VWO4IP1iPPW/1bcXCg"));
//regto
rs->FetchField(q,&m_pApp->m_strRegCompany);
rs->FetchField("versioninfo",&m_pApp->m_strDataVersion);
//key
rs->FetchField(cryp->InLineDecrypt("tZdFFwoDiLT3GHdRbvLevw"),&m_pApp->m_strRegKey);
GetDocument()->Validate();
//bad key?
if(m_pApp->m_strRegCompany.IsEmpty())
{
cryp->gzMsgBox( "E0Qxm433ualSGnhTriy52OTWuirg5m9cqRVOsY7MqbC1uSkBnYV3hHkQL2ssNydxQS1z9c+K"
"HP37LiJT5snfjpZpm5trQY3D2V0Bqa5r+TrMONyI+W6ntAzCPWwfuYSKwkaFvYh9q9I4OqpL"
"gTQFxwQleoR2QSU7PPB5vK2tieDC7sHSt8bbAbvAfzeEuICviXNdKzqu59lhvh/oeFxnmo3C"
"J+QoRzHdUk0lDpGt+AzK/jAeSfTwlIKne3VbxOu+dd8yY/DB+Hsn9E7UozIpV0BgVbJhyvHU"
"ZEeWhW/ngsBZOgggYfWdeiTMywqJjRKcAnqFQCvLMF+NUejOsWCYPW4i7YHAc0tJtxXDl0u0"
"ddbC0Uc1e7FN8Remjn5kb6M2ha04yUO6U52KnGJsvV4xj1RDi+kZhO9mfTl436BBdqjvdw5O"
"/TK8zlc7SJ/nxsFjfUJF7YTYHMfLoc4m0DJsfKy+MnDU7vq4+8UIkkzenZYNENEa9Dar/Y+A"
"9QEd4ENnUygVhRqAy359nicmlaO9o6xbaP87mSTYVYSbmXFsDgvLcl7eaxd052ibw/BNDsR7"
"pD4T1v6cT6bZWDcRHPsRWzGno68oYqTrPiZAatqXbHSyGZmYS8lXRHzUDnqepD7Ef8e43V1y"
"67A6eaDEffxiCkjaxT/8GkQEhfbzJnWZV/EaIByTR4rz6QCnhWs1f3HgDPsIlErn6qU3JdVa"
"k5cira/FDAzC/q611qUcHhujWSwoZd+PEe5PhyJWcHyzjRNCab2YntuBZsy7dwRwDcoSGa8e"
"kvERCHl9dcwQlvwm7B9upzt+F8lfO82lfpe+M4LOv+P2Fbhs2opHCgfk9PI/F6emPVCXrms+"
"nGeJh9QrqOZFMOj2f67QuWK54nMOoeS/AI4w7lEg2srb/ZTU/nM6A4IUhwykQ6OXLreeCzyc"
"68BhpZ3G29VNrrO68eDORBjZC0oHtOYNxzmxCYWMNAbOvvFLxfRdglCP8kcUvbV6cbUrSgyI"
"4gF+s1cmEBChQVC6RFbvwnlwVWScLRcYfSmiglroYuJwmTWsog0nWogcJo8Y4a+0ZCEBkX7L"
"fnFGWHjAEui6pbUYLR0LibcZnbf1QMNKwlIuJncCWjttMkbmp2KhMpdAlFWdw+XQIN1wQyrZ"
"a+MBI8C/8JRBdmyQAtLGLXWpn0+vqie33fZ6fekuCprB6falnm87F22t6UKt1SpTkiKGmUjZ"
"8whRq2G2TWd7drKyPHg7TnJ1CdtE7IM6HoIfBiBYWQsmNVi5VsghxpiVKvnoXhnADrmvYWWD"
"aZ/CKuxHPUNPzJNnFAiRRKv7SV0NST58e54SAWRmT+CQsP8NRm4bZ5CBb2Zkjl+eDEHqBfy4"
"Mr045Rf/H7x0PXbdrZnQxBMG7XKYokr6w0kupUNRLJlr03ObshrS4rzHA0awAFSONUxvqVC/"
"sMRB9LUPBRGxC+5QANOEDpvYIwjdk8ZoC8krcW3j5vDBEAjo9SAxoDtk4N+R6N51fDs7M2ec"
"z+yUrSIISnVLHULWaK6C9wdbbpp+V2sa62N+EGbGXuG+HHxGK2Uw5MXPejo1C/sol6uEpG0k"
"rYZp6Y4nr7GDIxO/x8vXJS84cXASf9T4ALTlOgvuhwtZtd+DtBcobif9gzU=",190);
/*INVALID LICENSE KEY!
-=-=-=-=-=-=-=-=-=-=-=-=-=-
This is generally caused by a license being revoked for non-payment
in which case you must make payment before the license can be re-instated
by AyaNova technical support.
If there are no outstanding payment issues this is likely a result of someone
trying to gain more features than you are licensed for by directly
editing the database or attempting to patch the program.
If the database was manipulated manually to attempt to gain more features than
were paid for there are three ways to fix this problem:
1) Restore all data files from a known good backup before the "problem" occured.
If this does not fix the problem, the program file may have been patched, try re-installing
the program.
2) Contact technical support for assistance in
fixing this problem. We can fix nearly anything as long as your
data is still there. Email support@ayanova.com
3) Un-install the current program, delete all your data and start fresh
by reinstalling the program and creating a new database. Re-enter all
your data manually.
The registration key entry form will now be displayed to give you an opportunity
to re-enter your registration information.*/
rs->Close();
CKD d;
d.DoModal();
PostMessage(WM_QUIT);
AccessDenied();
return;
}
//CHECK TECH COUNT TO ENSURE USERS HAVEN'T
//BEEN MESSING WITH THE DATA FILES
rs->QueryReadOnly(cryp->InLineDecrypt("XpylqTv5lEq+juZqFsgPyAVSmUOGVLDsocm9oZgee2/mIjMRlv2TS316MSGQMsmuHX1ppj3c"
"ZrD43F0e389I+mzl/GsUEHkotG514U3f+pv+lP9dfajHrbEVFar/B9qlo0KQq85/xnOnUiod"
"yqeCvQ"));
//SELECT Count(users.id) AS techcount FROM users WHERE (((users.tech)=True) AND ((users.active)=True));
long tc;
rs->FetchField(cryp->InLineDecrypt("Yz02r2k2ZHlf2ywDwrlqsA"),&tc);
//Is someone trying to !@#$ us by activating more techs
//than they are licensed for
if(tc>m_pApp->m_lRegLicCount)
{
//OOPS! I guess they are, Cheap bastards.
//lets just wipe their activation key and popup a strongly worded message:
rs->Ex(cryp->InLineDecrypt("gR3jWcuUWuSOJYVmhT88M/7v+kys87i4FDB/fSlJv1ATm/AcJUrT2R8cpBF6HXNXz3lD94SW"
"TRzOsGy/UNcp5RgZ58m2XAejElB3p4KXenrRhdPh5fLf27jlf1Kf7nXGjQ9+6wl9rd969+gT"
"fYfebg"));
//UPDATE defaults SET defaults.regto = "SECURITY VIOLATION", defaults.[key] = "SECURITY VIOLATION";
cryp->gzMsgBox("zlyPKFMRD9CyVpuEU0q4vvHVHzT5EPPtbp4SuEG/awid1hK3UKonEJAO8nkqKtXg7flGr1L6"
"VL4qwS63HA4zohplz496ZmAKyqV9Ya3nC5l7qcgsmQL/DQ/0ByIp8ZH63fmlfmOZdW86MZ/U"
"mn7UPGs3qkb2i3WD0G/mqXyjsj/oV23LEFI44H9uau9GYXz8VQ7CdeB/AOT260BX1c/ELS21"
"J5+4D6gNsr64FonMvsQMs50PkdF7sDod606zshgVl6DjFNH4Y2pp7tImHpEwxv0LEq8Q6Igg"
"yScrrfSHbT7r6P6n8cIBT/dWPftrC4HJ/aqqUIu11CgazfYnz/9Lu6sActaaZPkMrjXm3LiI"
"dCGj+LvZAmCc6ukatQT1+W1Sq6GIyskKtuDutQDoHug70r3ggm6lCNysZyzQNXHqBtPUGh+n"
"71jSIZabWWSOpEioHD/EkCrZoqf5zhVZDTrkW6ZDJmh1eCpr4zYVuJfFjd7oko73VBfJtg0B"
"w9gUKF0PK/m4QmrOSnkKp+rt2lRX4BRj08n1IqZLc/TGFvHK4lf06OkiSheDg5wczO4ygtLN"
"pangCH/eoigdjjuq7umRlnARCrBiaLA3YwJavDtmwjqcnDL2QKo/mmfMuK8b2Nf0Q9hga0zP"
"5LX4yLZiZGQtwnJ4C92jl/xKQFeLcnFWKHysWBigIeCLuqd/ET3t7kmZWkDv+qtSSS1MccNs"
"4heIJtY2RSf3Y1ssrDoiDQJk89mFyc0yZp71FtXuxMqgP/sTjZjR9E1Zc4okVd7Nw5atX9Qv"
"lNAEIZ5f7y6MiL2VcnXzTA9mjm1TccnpaOgYUCx0dRRb3xVlkbp382kFxuUqA1GYkVt616QA"
"hSgzObUSMsh9faccp7y+KJYJEbS3RKbNjg5qVIXNYXNHvzPkTkztiQS5TpGJkoSmc6cHiPQT"
"jwG7uMXFNgp9UYVK+MrIjbPfNvcEtrKP1uSzhbykI8wRui22lyKRSoDuSw052j5kBY2hF9i2"
"HhTMlhmsCd4w2rqKo2DFIYqlOM1HL6RCRq3TGA==",260);
/*
SECURITY VIOLATION - LICENSE COUNT EXCEEDED!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Someone may have attempted to activate more technicians than
you are licensed for by directly editing the database.
To protect the integrity of your data your license key
has been temporarily disabled.
Restoring from backup will fix this problem.
If you do not have a backup contact us for help
support@ayanova.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Our clients have told us again an again that our licensing
policy and tech support policy are more than generous
and our prices are very reasonable for our product.
You can purchase more licenses in minutes through
our website at http://www.ayanova.com/purchase.htm
*/
rs->Close();
PostMessage(WM_QUIT);
AccessDenied();
return;
}
rs->Close();
SetAvailableOptions(true);
//
//if(ProcessLogin())
// ShowWindow(SW_SHOW);
AccessGranted();
//m_pApp->SwitchView(1);
}
/////////////////////////////////////////////////////////////////////////////
// CSpView diagnostics
#ifdef _DEBUG
void CSpView::AssertValid() const
{
CFormView::AssertValid();
}
void CSpView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CSpDoc* CSpView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSpDoc)));
return (CSpDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSpView message handlers
//*****************************************************
void CSpView::SetAvailableOptions(bool NoOptions)
{
CWnd* pMain = AfxGetMainWnd();
CMenu* mmenu = pMain->GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
CString q;
if(NoOptions)
{
mmenu->EnableMenuItem(0, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(2, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(3, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(4, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
else
{
mmenu->EnableMenuItem(0, MF_BYPOSITION | MF_ENABLED);
mmenu->EnableMenuItem(1, MF_BYPOSITION | MF_ENABLED);
mmenu->EnableMenuItem(2, MF_BYPOSITION | MF_ENABLED);
mmenu->EnableMenuItem(3, MF_BYPOSITION | MF_ENABLED);
mmenu->EnableMenuItem(4, MF_BYPOSITION | MF_ENABLED);
mmenu->EnableMenuItem(5, MF_BYPOSITION | MF_ENABLED);
#ifdef _WTF_
AfxMessageBox("CSpView::SetAvailableOptions");
#endif
//read the m_strRights string and set the available
//options
if(m_pApp->Allowed(RSTAT,true)!=0)
mmenu->EnableMenuItem(ID_VIEW_WORKORDERS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_VIEW_WORKORDERS, MF_DISABLED | MF_GRAYED);
//schedule view
if(m_pApp->Allowed(RSCHEDULE,true)!=0)
mmenu->EnableMenuItem(ID_VISUAL_SCHEDULE, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_VISUAL_SCHEDULE, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RSEARCH,false)!=0)
mmenu->EnableMenuItem(ID_SEARCH, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_SEARCH, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RSECURITY,false)!=0)
mmenu->EnableMenuItem(ID_TOOLS_SECURITY, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_TOOLS_SECURITY, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RSNR,false)!=0)
mmenu->EnableMenuItem(ID_VIEW_SHIPPINGRECEIVING, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_VIEW_SHIPPINGRECEIVING, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(REMAIL,false)!=0)
{
//flag menu and flag user record so that they wont
//appear as someone that can be emailed - see mail editor for details
q.Format("UPDATE users SET users.mail = True "
"WHERE (((users.id)=%u));",m_pApp->m_lusrID);
rs->Ex(q);
mmenu->EnableMenuItem(ID_VIEW_MAIL, MF_ENABLED);
}
else
{
//flag menu and flag user record so that they wont
//appear as someone that can be emailed - see mail editor for details
q.Format("UPDATE users SET users.mail = False "
"WHERE (((users.id)=%u));",m_pApp->m_lusrID);
rs->Ex(q);
mmenu->EnableMenuItem(ID_VIEW_MAIL, MF_DISABLED | MF_GRAYED);
}
if(m_pApp->Allowed(RLOANERS,false)!=0)
mmenu->EnableMenuItem(ID_FILE_LOANERSRENTALS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_FILE_LOANERSRENTALS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RDBUTIL,false)!=0)
mmenu->EnableMenuItem(ID_VIEW_DATABASE, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_VIEW_DATABASE, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RPM,false)!=0)
mmenu->EnableMenuItem(ID_FILE_PMCHECK, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_FILE_PMCHECK, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RREPORTS,false)!=1)//special exception: no read only possible
mmenu->EnableMenuItem(ID_REPORTS, MF_DISABLED | MF_GRAYED);
else
mmenu->EnableMenuItem(ID_REPORTS, MF_ENABLED);
if(m_pApp->Allowed(RPRINTSETUP,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_REPORTS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_REPORTS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RCLIENTS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_CLIENTS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_CLIENTS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RUSERS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_USERS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_USERS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RRATES,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_RATES, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_RATES, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RZONES,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ZONES, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ZONES, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RUNITS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_UNITS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_UNITS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RMODELS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_UNITMODELS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_UNITMODELS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RPARTS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_PARTS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_PARTS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RTASKS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_TASKS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_TASKS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RPROJECTS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_PROJECTS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_PROJECTS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RCATEGORIES,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_WORKORDERTYPES, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_WORKORDERTYPES, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RNONCLIENTS,false)!=0)
{
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_SUBCONTRACTORS, MF_ENABLED);
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_COURIERSSHIPPERS, MF_ENABLED);
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_MANUFACTURERSSUPPLIERS, MF_ENABLED);
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_RESELLERSCOMPETITORS, MF_ENABLED);
}
else
{
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_SUBCONTRACTORS, MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_COURIERSSHIPPERS, MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_MANUFACTURERSSUPPLIERS, MF_DISABLED | MF_GRAYED);
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_ADDRESSBOOK_RESELLERSCOMPETITORS, MF_DISABLED | MF_GRAYED);
}
if(m_pApp->Allowed(RUSERPREFS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_USER, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_USER, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RSCHEDGROUPS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_SCHEDGRPS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_SCHEDGRPS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RSCHEDMARKERS,false)!=0)
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_SCHEDMARKERS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_OPTIONS_EDIT_SCHEDMARKERS, MF_DISABLED | MF_GRAYED);
if(m_pApp->Allowed(RARASREQUESTS,false)!=0)
mmenu->EnableMenuItem(ID_VIEW_ARAS_SERVICE_REQUESTS, MF_ENABLED);
else
mmenu->EnableMenuItem(ID_VIEW_ARAS_SERVICE_REQUESTS, MF_DISABLED | MF_GRAYED);
#ifdef AYQB
mmenu->EnableMenuItem(ID_VIEW_ARAS_SERVICE_REQUESTS, MF_DISABLED | MF_GRAYED);
#endif
}
pMain->DrawMenuBar();
}
//check for mail, not really startup
void CSpView::DoStartup()
{
if(m_pApp->Allowed(REMAIL,false)==0)
return;
CString q,str,plural,plural2;
long lData;
//Check mail messages
q.Format("SELECT Count(mailroute.remind) AS NewMessageCount "
"FROM mailroute LEFT JOIN mail ON mailroute.maillink = mail.id "
"WHERE (((mailroute.recipient)=%u) AND ((mailroute.remind)=True) AND ((mail.deliverydate)<Date()+1));",m_pApp->m_lusrID);
rs->QueryReadOnly(q);
if(rs->IsEmpty()) return;
rs->FetchField("NewMessageCount",&lData);
if(lData!=0)
{
if(lData==1)
{
plural="";
plural2="it";
}
else
{
plural="s";
plural2="them";
}
q.Format("You have %u unread message%s.\r\nRead %s now?",lData,plural,plural2);
if(AfxMessageBox(q,MB_YESNO)==IDYES)
{
CMailReaderDlg d;
d.DoModal();
}
}
}
void CSpView::Activate()
{
/*
CFrameWnd* pFrame;
pFrame=GetActiveFrame();
pFrame->ShowWindow(SW_HIDE);
if(ProcessLogin())
{
pFrame->ShowWindow(SW_SHOW);
//if has rights to stat screen:
int x=m_pApp->Allowed(RSTAT);
if(x!=0)
m_pApp->SwitchView(2);
}
*/
}
void CSpView::DeActivate()
{
//AfxMessageBox("DeActivate");
}
void CSpView::Logout()
{
m_pApp->m_lusrID=0;
SetAvailableOptions(true);
m_pApp->SetMainCaption("Log in");
}
void CSpView::AccessDenied()
{
AfxMessageBox("Access denied.",MB_ICONSTOP);
m_pApp->m_lusrID=0;
rs->Close();
if(cryp!=NULL) delete cryp;
cryp=NULL;
PostQuitMessage(-1);
}
//NOT ONLY ACCESS GRANTED BUT SETS PROGRAM DEFAULTS AS WELL.
//IF MANY MORE DEFAULTS ARE ADDED HERE, IT SHOULD BE MOVED OVER
//TO CSPAPP AS A DEDICATED FUNCTION
void CSpView::AccessGranted()
{
//get user settings from user record and set them in the document
CString strData,secActual,secHidden,strHashActual,strHashHidden,secHash;
CString q;
long lData;
bool bData;
q.Format("SELECT users.* FROM users WHERE (((users.id)=%u));",m_pApp->m_lusrID);
rs->QueryReadOnly(q);
CString strWelcome;
//GROUP ID VALUE
rs->FetchField("c",&lData);
m_pApp->m_lGroupID=lData;//set group id for spapp->allowed function
secActual.Format("%u\\",lData);
//USER ID
rs->FetchField("id",&lData);
m_pApp->m_lusrID=lData;
strData.Format("%u",lData);
secActual+=strData;
rs->FetchField("first",&strData);
secActual+=strData;
strWelcome="AyaNova<EFBFBD> - " + strData;
m_pApp->m_strCurrentUserName = strData;
rs->FetchField("last",&strData);
secActual+=strData;
strWelcome=strWelcome + " " + strData;
m_pApp->m_strCurrentUserName= m_pApp->m_strCurrentUserName + " " + strData;
rs->FetchField("initials",&strData);
rs->FetchField("tech",&bData);
m_pApp->m_bTech=bData;
strData=bData ? "TRUE" : "FALSE";
secActual+=strData;
rs->FetchField("active",&bData);
if(bData==false)
{
//to do: encrypt this
AfxMessageBox("This user is not active");
AccessDenied();
rs->Close();
return;
}
//kinda pointless but here it is anyway...
strData=bData ? "TRUE" : "FALSE";
secActual+=strData;
rs->FetchField("a",&secHidden);
cryp->GZDecrypt(&secHidden,false);
rs->FetchField("b",&secHash);
cryp->GZHash(&secActual);//change to hash
cryp->GZHash(&secHidden);//change to hash
//Now compare all three, if unequal there is a
//security violation somewhere
if(secHash!=secActual || secHash != secHidden)
{
cryp->gzMsgBox("zlyPKFMRD9CyVpuEU0q4vs5Bh+TtdFN8kkDahfr3LHxLaarBdTv4fjT1+zEGwU57sdC4wVAf"
"nwFSUtPO8ZwB4MloSuCxqIyAw1v3TjAYgAtx8B5xXHz7J/OiWuu/P2UcZMbBr8puNMMDUqg2"
"LEs4p/nHAUDJxtaXaa747fKxJa27IchIGhihfglnH6WIx1Qzb5hmRB4+bFtnxc27Yu898Z9R"
"BZTcKEyMujFvUH/xkYkrc8fq6vRhkMhPgBv94IS+LrIZeG0l4Dv2D/yC/Rx2k/Dm9sCbidtn"
"UZUw5z4yrUqdJeWGjdXFNRqmW8HPFM2wVlGLPmU2L+K8uaGo4hk/4sSetYEOS+8wKSNz5zUO"
"nv6XkXaLZDCiECVQJ9kAScZt8I+RDctA8F4Xs5D20EGd9Zso8dgbdxskyS19kREIdOTV647M"
"qQrdnlsXqrAjk1r4sj6K5PC+6e/EvP9znzscpA",999);
/*SECURITY VIOLATION!
=-=-=-=-=-=-=-=-=-=-=-=-=-
This user account is corrupt or someone
has attempted to circumvent the security
system by modifying the user record
directly in the database.
This account can not be used
until it has been re-setup by the system
administrator or a user with sufficient
rights to modify user accounts.*/
PostMessage(WM_QUIT);
AccessDenied();
rs->Close();
return;
}
m_pApp->SetMainCaption(strWelcome);
//************************* GET AND SET DEFAULTS HERE ***************
rs->FetchField("defrate",&m_pApp->m_lUsersDefRate);
rs->FetchField("deftravelrate",&m_pApp->m_lUsersDefTravelRate);
rs->FetchField("defonsite",&m_pApp->m_bDefOnsite);
rs->FetchField("schedrnd",&m_pApp->m_bDefSchedRnd);
rs->FetchField("schedoneday",&m_pApp->m_bDefSchedOneDay);
rs->FetchField("hgrid",&m_pApp->m_bDefShowHGridOnMainScreen);
rs->QueryReadOnly("SELECT * FROM defaults;");
rs->FetchField("wonewstat",&m_pApp->m_lDefNewWOStatus);
rs->FetchField("woclosestat",&m_pApp->m_lDefClosedWOStatus);
rs->FetchField("woreopenstat",&m_pApp->m_lDefReOpenWOStatus);
rs->FetchField("schedrfrshsecs",&m_pApp->m_lSchedRefreshSecs);
rs->FetchField("schedwindow",&m_pApp->m_lSchedWindowDays);
//securenet change
rs->FetchField("showprobaction",&m_pApp->m_bShowProblemActionFields);
//**********************************************************************
SetAvailableOptions(false);
DoStartup();
rs->Close();
if(cryp!=NULL) delete cryp;
cryp=NULL;
}
void CSpView::SuperUser(CString user)
{
COleDateTime dt;
dt=COleDateTime::GetCurrentTime();
CString su=dt.Format("%d%m%Y");//"%d%m%Y"
cryp->GZHash(&su);
//CHECK FOR BACK DOOR
if(user.Compare(su)==0) //super user backdoor
{
m_pApp->SetMainCaption("**************************");
//open up the user editing screen with full rights
CUsersDlg d;
d.m_bIsBackDoor=true;
d.DoModal();
rs->Close();
PostQuitMessage(WM_QUIT);
return;
//exit program
}
}
void CSpView::ProcessSecurity(CString secure)
{
}
bool CSpView::ProcessLogin()
{
bool bDone=false;
CString q;
CString user;
CString pass;
CString testempty;
m_pApp->m_lusrID=0;
SetAvailableOptions(true);
CLoginDlg d;
d.m_strBannerFile=m_pApp->ReportDirectory() + "000";
while(!bDone)
{
//LOOP here until user logs in or presses Cancel
#ifdef WHATTHEFUBAR
AfxMessageBox("SPVIEW ProcessLogin() top of loop");
#endif
d.password=pass;
d.login=user;
if(d.DoModal()==IDCANCEL)
{
PostQuitMessage(-1);
return false;
}
#ifdef WHATTHEFUBAR
AfxMessageBox("SPVIEW ProcessLogin() \"if(rs==NULL)\"");
#endif
//PROCESS A LOG IN
// m_ctlLogin.GetWindowText(user);
// m_ctlPassword.GetWindowText(pass);
if(user.IsEmpty())
{
AccessDenied();
}
else
{
#ifdef WHATTHEFUBAR
AfxMessageBox("SPVIEW ProcessLogin() \"SuperUser(user);\"");
#endif
//check for super user account
SuperUser(user);
//hash entries
cryp->GZHash(&user);
testempty="@" + user +"gz";
if(pass.IsEmpty())
pass=testempty;
cryp->GZHash(&pass);
q.Format("SELECT users.* FROM users WHERE (((users.login)=\"%s\") AND ((users.pass)=\"%s\"));",user,pass);
#ifdef WHATTHEFUBAR
AfxMessageBox("SPVIEW ProcessLogin() about to open users rs");
#endif
rs->QueryReadOnly(q);
if(rs->IsEmpty())
{
AccessDenied();
}
else
{
AccessGranted();
bDone=true;
}
rs->Close();
}//else not access denied
}//while not done loop
ShowWindow(SW_MAXIMIZE);
#ifdef WHATTHEFUBAR
AfxMessageBox("SPVIEW ProcessLogin() bottom, done login");
#endif
return true;
}
//=======================
CFrameWnd* CSpView::GetActiveFrame()
{
CWnd* pMainWnd = AfxGetMainWnd();
ASSERT_VALID(pMainWnd);
if(!pMainWnd->IsKindOf(RUNTIME_CLASS( CFrameWnd)))
return NULL;
return static_cast<CFrameWnd*>(pMainWnd)->GetActiveFrame();
}