123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField;
- use Chamilo\UserBundle\Entity\User;
- /**
- * @package chamilo.webservices
- */
- require_once '../inc/global.inc.php';
- $libpath = api_get_path(LIBRARY_PATH);
- $debug = false;
- define('WS_ERROR_SECRET_KEY', 1);
- define('WS_ERROR_NOT_FOUND_RESULT', 2);
- define('WS_ERROR_INVALID_INPUT', 3);
- define('WS_ERROR_SETTING', 4);
- function return_error($code) {
- $fault = null;
- switch ($code) {
- case WS_ERROR_SECRET_KEY:
- $fault = new soap_fault('Server', '', 'Secret key is not correct or params are not correctly set');
- break;
- case WS_ERROR_NOT_FOUND_RESULT:
- $fault = new soap_fault('Server', '', 'No result was found for this query');
- break;
- case WS_ERROR_INVALID_INPUT:
- $fault = new soap_fault('Server', '', 'The input variables are invalid o are not correctly set');
- break;
- case WS_ERROR_SETTING:
- $fault = new soap_fault('Server', '', 'Please check the configuration for this webservice');
- break;
- }
- return $fault;
- }
- /**
- * @param array $params
- * @return bool
- */
- function WSHelperVerifyKey($params)
- {
- global $_configuration, $debug;
- if (is_array($params)) {
- $secret_key = $params['secret_key'];
- } else {
- $secret_key = $params;
- }
- //error_log(print_r($params,1));
- $check_ip = false;
- $ip_matches = false;
- $ip = trim($_SERVER['REMOTE_ADDR']);
- // if we are behind a reverse proxy, assume it will send the
- // HTTP_X_FORWARDED_FOR header and use this IP instead
- if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $ip = trim($ip1);
- }
- if ($debug)
- error_log("ip: $ip");
- // Check if a file that limits access from webservices exists and contains
- // the restraining check
- if (is_file('webservice-auth-ip.conf.php')) {
- include 'webservice-auth-ip.conf.php';
- if ($debug)
- error_log("webservice-auth-ip.conf.php file included");
- if (!empty($ws_auth_ip)) {
- $check_ip = true;
- $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip);
- if ($debug)
- error_log("ip_matches: $ip_matches");
- }
- }
- if ($debug) {
- error_log("checkip " . intval($check_ip));
- }
- if ($check_ip) {
- $security_key = $_configuration['security_key'];
- } else {
- $security_key = $ip.$_configuration['security_key'];
- //error_log($secret_key.'-'.$security_key);
- }
- $result = api_is_valid_secret_key($secret_key, $security_key);
- //error_log($secret_key.'-'.$security_key);
- if ($debug)
- error_log('WSHelperVerifyKey result: '.intval($result));
- return $result;
- }
- // Create the server instance
- $server = new soap_server();
- /** @var HookWSRegistration $hook */
- $hook = HookWSRegistration::create();
- if (!empty($hook)) {
- $hook->setEventData(array('server' => $server));
- $res = $hook->notifyWSRegistration(HOOK_EVENT_TYPE_PRE);
- if (!empty($res['server'])) {
- $server = $res['server'];
- }
- }
- $server->soap_defencoding = 'UTF-8';
- // Initialize WSDL support
- $server->configureWSDL('WSRegistration', 'urn:WSRegistration');
- /* Register WSCreateUsers function */
- // Register the data structures used by the service
- // Prepare input params
- $server->wsdl->addComplexType(
- 'extras',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
- 'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'extrasList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:extras[]')),'tns:extras'
- );
- $server->wsdl->addComplexType(
- 'usersParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'language' => array('name' => 'language', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'usersParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:usersParams[]')),'tns:usersParams'
- );
- $server->wsdl->addComplexType(
- 'createUsers',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'users' => array('name' => 'users', 'type' => 'tns:usersParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_createUsers',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array(
- 'name' => 'original_user_id_value',
- 'type' => 'xsd:string',
- ),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_createUsers',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:result_createUsers[]')),'tns:result_createUsers'
- );
- // Register the method to expose
- $server->register('WSCreateUsers', // method name
- array('createUsers' => 'tns:createUsers'), // input parameters
- array('return' => 'tns:results_createUsers'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateUsers', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds a user' // documentation
- );
- // Define the method WSCreateUsers
- function WSCreateUsers($params) {
- global $_user;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $users_params = $params['users'];
- $results = array();
- $orig_user_id_value = array();
- $userManager = UserManager::getManager();
- $userRepository = UserManager::getRepository();
- foreach ($users_params as $user_param) {
- $firstName = $user_param['firstname'];
- $lastName = $user_param['lastname'];
- $status = $user_param['status'];
- $email = $user_param['email'];
- $loginName = $user_param['loginname'];
- $password = $user_param['password'];
- $official_code = '';
- $language = '';
- $phone = '';
- $picture_uri = '';
- $auth_source = PLATFORM_AUTH_SOURCE;
- $expiration_date = '';
- $active = 1;
- $hr_dept_id = 0;
- $extra = null;
- $original_user_id_name = $user_param['original_user_id_name'];
- $original_user_id_value = $user_param['original_user_id_value'];
- $orig_user_id_value[] = $user_param['original_user_id_value'];
- $extra_list = $user_param['extra'];
- if (!empty($user_param['language'])) {
- $language = $user_param['language'];
- }
- if (!empty($user_param['phone'])) {
- $phone = $user_param['phone'];
- }
- if (!empty($user_param['expiration_date'])) {
- $expiration_date = $user_param['expiration_date'];
- }
- // Check if exits x_user_id into user_field_values table.
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($user_id > 0) {
- /** @var User $user */
- $user = $userRepository->find($user_id);
- if ($user && $user->isActive() == false) {
- if (!is_null($password)) {
- $user->setPlainPassword($password);
- }
- if (!is_null($auth_source)) {
- $user->setAuthSource($auth_source);
- }
- if (!empty($user_param['expiration_date'])) {
- $expiration_date = new DateTime($user_param['expiration_date']);
- }
- $user->setLastname($lastName)
- ->setFirstname($firstName)
- ->setUsername($loginName)
- ->setEmail($email)
- ->setStatus($status)
- ->setOfficialCode($official_code)
- ->setPhone($phone)
- ->setExpirationDate($expiration_date)
- ->setHrDeptId($hr_dept_id)
- ->setActive(true);
- $userManager->updateUser($user, true);
- $results[] = $user_id;
- continue;
- //return $r_check_user[0];
- } else {
- $results[] = 0;
- continue;
- //return 0;
- // user id already exits.
- }
- }
- // Default language.
- if (empty($language)) {
- $language = api_get_setting('platformLanguage');
- }
- if (!empty($_user['user_id'])) {
- $creator_id = $_user['user_id'];
- } else {
- $creator_id = '';
- }
- // First check wether the login already exists.
- if (!UserManager::is_username_available($loginName)) {
- if (api_set_failure('login-pass already taken')) {
- $results[] = 0;
- continue;
- }
- }
- $userId = UserManager::create_user(
- $firstName,
- $lastName,
- $status,
- $email,
- $loginName,
- $password,
- $official_code,
- $language,
- $phone,
- $picture_uri,
- $auth_source,
- $expiration_date,
- $active,
- $hr_dept_id
- );
- if ($userId) {
- if (api_is_multiple_url_enabled()) {
- if (api_get_current_access_url_id() != -1) {
- UrlManager::add_user_to_url($userId, api_get_current_access_url_id());
- } else {
- UrlManager::add_user_to_url($userId, 1);
- }
- } else {
- // We add by default the access_url_user table with access_url_id = 1
- UrlManager::add_user_to_url($userId, 1);
- }
- // Save new field label into user_field table.
- UserManager::create_extra_field(
- $original_user_id_name,
- 1,
- $original_user_id_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $userId,
- $original_user_id_name,
- $original_user_id_value
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save new field label into user_field table.
- UserManager::create_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $userId,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- } else {
- $results[] = 0;
- continue;
- }
- $results[] = $userId;
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_value' => $orig_user_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSCreateUser function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'createUser',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'language' => array('name' => 'language', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'active' => array('name' => 'extra', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSCreateUser', // method name
- array('createUser' => 'tns:createUser'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateUser', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds a user' // documentation
- );
- // Define the method WSCreateUser
- function WSCreateUser($params) {
- global $_user, $_configuration, $debug;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $firstName = $params['firstname'];
- $lastName = $params['lastname'];
- $status = $params['status'];
- $email = $params['email'];
- $loginName = $params['loginname'];
- $password = $params['password'];
- $official_code = '';
- $language = '';
- $phone = '';
- $picture_uri = '';
- $auth_source = PLATFORM_AUTH_SOURCE;
- $expiration_date = null;
- $expirationDateStatement = '';
- $active = !isset($params['active']) || !intval($params['active']) ? 0 : 1;
- $hr_dept_id = 0;
- $extra = null;
- $original_user_id_name = $params['original_user_id_name'];
- $original_user_id_value = $params['original_user_id_value'];
- $extra_list = $params['extra'];
- if (!empty($params['language'])) {
- $language = $params['language'];
- }
- if (!empty($params['phone'])) {
- $phone = $params['phone'];
- }
- if (!empty($params['expiration_date'])) {
- $expiration_date = $params['expiration_date'];
- //$expirationDateStatement = " expiration_date = '".Database::escape_string($expiration_date)."', ";
- }
- // check if exits x_user_id into user_field_values table
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- $userManager = UserManager::getManager();
- $userRepository = UserManager::getRepository();
- if ($user_id > 0) {
- /** @var User $user */
- $user = $userRepository->find($user_id);
- if ($user && $user->isActive() == false) {
- if (!is_null($password)) {
- $user->setPlainPassword($password);
- }
- if (!is_null($auth_source)) {
- $user->setAuthSource($auth_source);
- }
- if (!empty($params['expiration_date'])) {
- $expiration_date = new DateTime($params['expiration_date']);
- }
- $user->setLastname($lastName)
- ->setFirstname($firstName)
- ->setUsername($loginName)
- ->setEmail($email)
- ->setStatus($status)
- ->setOfficialCode($official_code)
- ->setPhone($phone)
- ->setExpirationDate($expiration_date)
- ->setHrDeptId($hr_dept_id)
- ->setActive(true);
- $userManager->updateUser($user, true);
- return $user_id;
- } else {
- return 0;
- }
- }
- // Default language
- if (empty($language)) {
- $language = api_get_setting('platformLanguage');
- }
- if (!empty($_user['user_id'])) {
- $creator_id = $_user['user_id'];
- } else {
- $creator_id = '';
- }
- // First check wether the login already exists
- if (!UserManager::is_username_available($loginName)) {
- if ($debug) error_log("Username $loginName is not available");
- return 0;
- }
- if (isset($original_user_id_name) && isset($original_user_id_value)) {
- $_SESSION['ws_' . $original_user_id_name] = $original_user_id_value;
- }
- /** @var User $user */
- $userId = UserManager::create_user(
- $firstName,
- $lastName,
- $status,
- $email,
- $loginName,
- $password,
- $official_code,
- $language,
- $phone,
- $picture_uri,
- $auth_source,
- $expiration_date,
- $active,
- $hr_dept_id
- );
- if ($userId) {
- if (api_is_multiple_url_enabled()) {
- if (api_get_current_access_url_id() != -1) {
- UrlManager::add_user_to_url($userId, api_get_current_access_url_id());
- } else {
- UrlManager::add_user_to_url($userId, 1);
- }
- } else {
- // We add by default the access_url_user table with access_url_id = 1
- UrlManager::add_user_to_url($userId, 1);
- }
- // Save new fieldlabel into user_field table.
- UserManager::create_extra_field(
- $original_user_id_name,
- 1,
- $original_user_id_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $userId,
- $original_user_id_name,
- $original_user_id_value
- );
- if (isset($original_user_id_name) && isset($original_user_id_value)) {
- unset($_SESSION['ws_' . $original_user_id_name]);
- }
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save new field label into user_field table.
- UserManager::create_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $userId,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- } else {
- return 0;
- }
- return $userId;
- }
- /* Register WSCreateUsersPasswordCrypted function */
- // Register the data structures used by the service
- // Prepare input params.
- // Input params for editing users
- $server->wsdl->addComplexType(
- 'createUsersPassEncryptParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
- 'language' => array('name' => 'language', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'official_code' => array('name' => 'official_code', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value'=> array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'createUsersPassEncryptParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:createUsersPassEncryptParams[]')),
- 'tns:createUsersPassEncryptParams'
- );
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'createUsersPasswordCrypted',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'users' => array('name' => 'users', 'type' => 'tns:createUsersPassEncryptParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_createUsersPassEncrypt',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_createUsersPassEncrypt',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createUsersPassEncrypt[]')),
- 'tns:result_createUsersPassEncrypt'
- );
- // Register the method to expose
- $server->register('WSCreateUsersPasswordCrypted', // method name
- array('createUsersPasswordCrypted' => 'tns:createUsersPasswordCrypted'), // input parameters
- array('return' => 'tns:results_createUsersPassEncrypt'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateUsersPasswordCrypted', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds users to the system' // documentation
- );
- // Define the method WSCreateUsersPasswordCrypted
- function WSCreateUsersPasswordCrypted($params)
- {
- global $_user, $_configuration;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- // database table definition
- $table_user = Database::get_main_table(TABLE_MAIN_USER);
- $t_uf = Database::get_main_table(TABLE_EXTRA_FIELD);
- $t_ufv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
- $users_params = $params['users'];
- $results = array();
- $orig_user_id_value = array();
- foreach ($users_params as $user_param) {
- $password = $user_param['password'];
- $encrypt_method = $user_param['encrypt_method'];
- $firstName = $user_param['firstname'];
- $lastName = $user_param['lastname'];
- $status = $user_param['status'];
- $email = $user_param['email'];
- $loginName = $user_param['loginname'];
- $official_code = $user_param['official_code'];
- $language = '';
- $phone = '';
- $picture_uri = '';
- $auth_source = PLATFORM_AUTH_SOURCE;
- $expiration_date = '';
- $active = 1;
- $hr_dept_id = 0;
- $extra = null;
- $original_user_id_name = $user_param['original_user_id_name'];
- $original_user_id_value = $user_param['original_user_id_value'];
- $orig_user_id_value[] = $user_param['original_user_id_value'];
- $extra_list = $user_param['extra'];
- $salt = '';
- if (!empty($_configuration['password_encryption'])) {
- if ($_configuration['password_encryption'] === $encrypt_method ) {
- if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- $results[] = $msg;
- continue;
- } else if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- $results[] = $msg;
- continue;
- }
- } else {
- $msg = "This encryption $encrypt_method is not configured";
- $results[] = $msg;
- continue;
- }
- } else {
- $msg = 'The chamilo setting $_configuration["password_encryption"] is not configured';
- $results[] = $msg;
- continue;
- }
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- if($extra['field_name'] == 'salt') {
- $salt = $extra['field_value'];
- break;
- }
- }
- }
- if (!empty($user_param['language'])) {
- $language = $user_param['language'];
- }
- if (!empty($user_param['phone'])) {
- $phone = $user_param['phone'];
- }
- if (!empty($user_param['expiration_date'])) {
- $expiration_date = $user_param['expiration_date'];
- }
- $extraFieldType = EntityExtraField::USER_FIELD_TYPE;
- // Check whether x_user_id exists into user_field_values table.
- $sql = "SELECT value as field_value,item_id as user_id
- FROM $t_uf uf, $t_ufv ufv
- WHERE
- uf.extra_field_type = $extraFieldType
- ufv.field_id=uf.id AND
- variable='$original_user_id_name' AND
- value ='$original_user_id_value'";
- $res = Database::query($sql);
- $row = Database::fetch_row($res);
- $count_row = Database::num_rows($res);
- if ($count_row > 0) {
- // Check if user is not active.
- $sql = "SELECT user_id FROM $table_user WHERE user_id ='".$row[1]."' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- $count_check_user = Database::num_rows($resu);
- if ($count_check_user > 0) {
- $sql = "UPDATE $table_user SET
- lastname='".Database::escape_string($lastName)."',
- firstname='".Database::escape_string($firstName)."',
- username='".Database::escape_string($loginName)."',";
- if (!is_null($auth_source)) {
- $sql .= " auth_source='".Database::escape_string($auth_source)."',";
- }
- $sql .= "
- password='".Database::escape_string($password)."',
- email='".Database::escape_string($email)."',
- status='".Database::escape_string($status)."',
- official_code='".Database::escape_string($official_code)."',
- phone='".Database::escape_string($phone)."',
- expiration_date='".Database::escape_string($expiration_date)."',
- active='1',
- hr_dept_id=".intval($hr_dept_id);
- $sql .= " WHERE user_id='".$r_check_user[0]."'";
- Database::query($sql);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into user_field_value table.
- $res = UserManager::update_extra_field_value(
- $r_check_user[0],
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = $r_check_user[0];
- continue;
- } else {
- $results[] = 0;
- continue; // User id already exits.
- }
- }
- // Default language.
- if (empty($language)) {
- $language = api_get_setting('platformLanguage');
- }
- if (!empty($_user['user_id'])) {
- $creator_id = $_user['user_id'];
- } else {
- $creator_id = '';
- }
- // First check wether the login already exists
- if (!UserManager::is_username_available($loginName)) {
- if (api_set_failure('login-pass already taken')) {
- $results[] = 0;
- continue;
- }
- }
- $sql = "INSERT INTO $table_user SET
- lastname = '".Database::escape_string(trim($lastName))."',
- firstname = '".Database::escape_string(trim($firstName))."',
- username = '".Database::escape_string(trim($loginName))."',
- status = '".Database::escape_string($status)."',
- password = '".Database::escape_string($password)."',
- email = '".Database::escape_string($email)."',
- official_code = '".Database::escape_string($official_code)."',
- picture_uri = '".Database::escape_string($picture_uri)."',
- creator_id = '".Database::escape_string($creator_id)."',
- auth_source = '".Database::escape_string($auth_source)."',
- phone = '".Database::escape_string($phone)."',
- language = '".Database::escape_string($language)."',
- registration_date = now(),
- expiration_date = '".Database::escape_string($expiration_date)."',
- hr_dept_id = '".Database::escape_string($hr_dept_id)."',
- active = '".Database::escape_string($active)."'";
- $result = Database::query($sql);
- if ($result) {
- //echo "id returned";
- $return = Database::insert_id();
- $sql = "UPDATE $table_user SET user_id = id WHERE id = $return";
- Database::query($sql);
- if (api_is_multiple_url_enabled()) {
- if (api_get_current_access_url_id() != -1) {
- UrlManager::add_user_to_url($return, api_get_current_access_url_id());
- } else {
- UrlManager::add_user_to_url($return, 1);
- }
- } else {
- // We add by default the access_url_user table with access_url_id = 1
- UrlManager::add_user_to_url($return, 1);
- }
- // Save new fieldlabel into user_field table.
- $field_id = UserManager::create_extra_field(
- $original_user_id_name,
- 1,
- $original_user_id_name,
- ''
- );
- // Save the remote system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $return,
- $original_user_id_name,
- $original_user_id_value
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save new fieldlabel into user_field table.
- $field_id = UserManager::create_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $return,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- } else {
- $results[] = 0;
- continue;
- }
- $results[] = $return;
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_value' => $orig_user_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSCreateUserPasswordCrypted function */
- // Register the data structures used by the service
- //prepare input params
- // Input params for editing users
- $server->wsdl->addComplexType(
- 'createUserPasswordCrypted',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'loginname' => array('name' => 'loginname', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'), //encripted password using the encrypt_method
- 'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
- 'language' => array('name' => 'language', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'official_code' => array('name' => 'official_code', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSCreateUserPasswordCrypted', // method name
- array('createUserPasswordCrypted' => 'tns:createUserPasswordCrypted'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateUserPasswordCrypted', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds users' // documentation
- );
- // Define the method WSCreateUserPasswordCrypted
- function WSCreateUserPasswordCrypted($params)
- {
- global $_user, $_configuration, $debug;
- $debug = 1;
- if ($debug) error_log('WSCreateUserPasswordCrypted');
- if ($debug) error_log(print_r($params,1));
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- // Database table definition.
- $table_user = Database::get_main_table(TABLE_MAIN_USER);
- $orig_user_id_value = array();
- $password = $params['password'];
- $encrypt_method = $params['encrypt_method'];
- $firstName = $params['firstname'];
- $lastName = $params['lastname'];
- $status = $params['status'];
- $email = $params['email'];
- $loginName = $params['loginname'];
- $official_code = isset($params['official_code']) ? $params['official_code'] : '';
- $language = '';
- $phone = $params['phone'];
- $picture_uri = '';
- $auth_source = PLATFORM_AUTH_SOURCE;
- $expiration_date = '';
- $active = 1;
- $hr_dept_id = 0;
- $extra = null;
- $original_user_id_name = $params['original_user_id_name'];
- $original_user_id_value = $params['original_user_id_value'];
- $orig_user_id_value[] = $params['original_user_id_value'];
- $extra_list = isset($params['extra']) ? $params['extra'] : '';
- if (!empty($_configuration['password_encryption'])) {
- if ($_configuration['password_encryption'] === $encrypt_method ) {
- if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- if ($debug) error_log($msg);
- return $msg;
- } else if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- if ($debug) error_log($msg);
- return $msg;
- }
- } else {
- $msg = "This encryption $encrypt_method is not configured";
- if ($debug) error_log($msg);
- return $msg;
- }
- } else {
- $msg = 'The chamilo setting $_configuration["password_encryption"] is not configured';
- if ($debug) error_log($msg);
- return $msg;
- }
- if (!empty($params['language'])) {
- $language = $params['language'];
- }
- if (!empty($params['phone'])) {
- $phone = $params['phone'];
- }
- if (!empty($params['expiration_date'])) {
- $expiration_date = $params['expiration_date'];
- }
- // Check whether x_user_id exists into user_field_values table.
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($debug) error_log('Ready to create user');
- if ($user_id > 0) {
- if ($debug) error_log('User found with id: '.$user_id);
- // Check whether user is not active
- //@todo why this condition exists??
- $sql = "SELECT user_id FROM $table_user
- WHERE user_id ='".$user_id."' AND active= '0' ";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- $count_check_user = Database::num_rows($resu);
- if ($count_check_user > 0) {
- if ($debug) error_log('User id: '.$user_id.' exists and is NOT active. Updating user and setting setting active = 1');
- $sql = "UPDATE $table_user SET
- lastname='".Database::escape_string($lastName)."',
- firstname='".Database::escape_string($firstName)."',
- username='".Database::escape_string($loginName)."',";
- if (!is_null($auth_source)) {
- $sql .= " auth_source='".Database::escape_string($auth_source)."',";
- }
- $sql .= "
- password='".Database::escape_string($password)."',
- email='".Database::escape_string($email)."',
- status='".Database::escape_string($status)."',
- official_code='".Database::escape_string($official_code)."',
- phone='".Database::escape_string($phone)."',
- expiration_date='".Database::escape_string($expiration_date)."',
- active='1',
- hr_dept_id=".intval($hr_dept_id);
- $sql .= " WHERE user_id='".$r_check_user[0]."'";
- if ($debug) error_log($sql);
- Database::query($sql);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $r_check_user[0],
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- return $r_check_user[0];
- } else {
- if ($debug) error_log('User exists but is active. Cant be updated');
- return 0;
- }
- } else {
- if ($debug) error_log("User not found with original_id = $original_user_id_value and original_name = $original_user_id_name");
- }
- // Default language.
- if (empty($language)) {
- $language = api_get_setting('platformLanguage');
- }
- if (!empty($_user['user_id'])) {
- $creator_id = $_user['user_id'];
- } else {
- $creator_id = '';
- }
- // First check wether the login already exists
- if (!UserManager::is_username_available($loginName)) {
- if ($debug) error_log("Username $loginName is not available");
- return 0;
- }
- $sql = "INSERT INTO $table_user SET
- lastname = '".Database::escape_string(trim($lastName))."',
- firstname = '".Database::escape_string(trim($firstName))."',
- username = '".Database::escape_string(trim($loginName))."',
- status = '".Database::escape_string($status)."',
- password = '".Database::escape_string($password)."',
- email = '".Database::escape_string($email)."',
- official_code = '".Database::escape_string($official_code)."',
- picture_uri = '".Database::escape_string($picture_uri)."',
- creator_id = '".Database::escape_string($creator_id)."',
- auth_source = '".Database::escape_string($auth_source)."',
- phone = '".Database::escape_string($phone)."',
- language = '".Database::escape_string($language)."',
- registration_date = '".api_get_utc_datetime()."',
- expiration_date = '".Database::escape_string($expiration_date)."',
- hr_dept_id = '".Database::escape_string($hr_dept_id)."',
- active = '".Database::escape_string($active)."'";
- if ($debug) error_log($sql);
- $result = Database::query($sql);
- if ($result) {
- $return = Database::insert_id();
- $sql = "UPDATE $table_user SET user_id = id WHERE id = $return";
- Database::query($sql);
- $url_id = api_get_current_access_url_id();
- UrlManager::add_user_to_url($return, $url_id);
- if ($debug) error_log("Adding user_id = $return to URL id $url_id ");
- // Save new fieldlabel into user_field table.
- $field_id = UserManager::create_extra_field(
- $original_user_id_name,
- 1,
- $original_user_id_name,
- ''
- );
- // Save the remote system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $return,
- $original_user_id_name,
- $original_user_id_value
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // save new fieldlabel into user_field table
- $field_id = UserManager::create_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name,
- ''
- );
- // save the external system's id into user_field_value table'
- UserManager::update_extra_field_value(
- $return,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- } else {
- return 0;
- }
- return $return;
- }
- /* Register WSEditUsers function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editUsersParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'editUsersParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editUsersParams[]')),
- 'tns:editUsersParams'
- );
- $server->wsdl->addComplexType(
- 'editUsers',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'users' => array('name' => 'users', 'type' => 'tns:editUsersParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- /* Register WSEditUserCredentials function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editUserCredentials',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSEditUserCredentials', // method name
- array('editUserCredentials' => 'tns:editUserCredentials'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditUserCredentials', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits the username and password of a user' // documentation
- );
- // Define the method WSEditUser
- function WSEditUserCredentials($params)
- {
- global $_configuration;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userManager = UserManager::getManager();
- $userRepository = UserManager::getRepository();
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- $original_user_id_value = $params['original_user_id_value'];
- $original_user_id_name = $params['original_user_id_name'];
- $username = $params['username'];
- $password = null;
- if (!empty($params['password'])) {
- $password = $params['password'];
- }
- // Get user id from the other system ID
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($user_id == 0) {
- return 0;
- } else {
- $sql = "SELECT user_id FROM $table_user
- WHERE user_id ='$user_id' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- return 0;
- }
- }
- // Check whether username already exits.
- $sql = "SELECT username FROM $table_user
- WHERE username = '$username' AND user_id <> '$user_id'";
- $res_un = Database::query($sql);
- $r_username = Database::fetch_row($res_un);
- if (!empty($r_username[0])) {
- return 0;
- }
- /** @var User $user */
- $user = $userRepository->find($user_id);
- if ($user) {
- $user->setUsername($username);
- if (!is_null($password)) {
- $user->setPlainPassword($password);
- }
- $userManager->updateUser($user, true);
- return true;
- }
- return false;
- }
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_editUsers',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_editUsers',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editUsers[]')),
- 'tns:result_editUsers'
- );
- // Register the method to expose
- $server->register('WSEditUsers', // method name
- array('editUsers' => 'tns:editUsers'), // input parameters
- array('return' => 'tns:results_editUsers'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditUsers', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a user from wiener' // documentation
- );
- // Define the method WSEditUsers
- function WSEditUsers($params)
- {
- global $_configuration;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userManager = UserManager::getManager();
- $userRepository = UserManager::getRepository();
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- $users_params = $params['users'];
- $results = array();
- $orig_user_id_value = array();
- foreach ($users_params as $user_param) {
- $original_user_id_value = $user_param['original_user_id_value'];
- $original_user_id_name = $user_param['original_user_id_name'];
- $orig_user_id_value[] = $original_user_id_value;
- $firstname = $user_param['firstname'];
- $lastname = $user_param['lastname'];
- $username = $user_param['username'];
- $password = null;
- $auth_source = null;
- $email = $user_param['email'];
- $status = $user_param['status'];
- $official_code = '';
- $phone = $user_param['phone'];
- $picture_uri = '';
- $expiration_date = $user_param['expiration_date'];
- $active = 1;
- $creator_id = null;
- $hr_dept_id = 0;
- $extra = null;
- $extra_list = $user_param['extra'];
- if (!empty($user_param['password'])) {
- $password = $user_param['password'];
- }
- // Get user id from id wiener
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($user_id == 0) {
- $results[] = 0; // Original_user_id_value doesn't exist.
- continue;
- } else {
- $sql = "SELECT user_id FROM $table_user
- WHERE user_id ='$user_id' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- $results[] = 0; // user_id is not active.
- continue;
- }
- }
- // Check whether username already exits.
- $sql = "SELECT username FROM $table_user
- WHERE username = '$username' AND user_id <> '$user_id'";
- $res_un = Database::query($sql);
- $r_username = Database::fetch_row($res_un);
- if (!empty($r_username[0])) {
- $results[] = 0; // username already exits.
- continue;
- }
- // Edit lastname and firstname only if not empty
- /** @var User $user */
- $user = $userRepository->find($user_id);
- if (!empty($lastname)) {
- $user->setLastname($lastname);
- //$sql .= " lastname='".Database::escape_string($lastname)."', ";
- }
- if (!empty($firstname)) {
- $user->setFirstname($firstname);
- //$sql .= " firstname='".Database::escape_string($firstname)."', ";
- }
- $user->setUsername($username);
- //$sql .= " username='".Database::escape_string($username)."',";
- if (!is_null($password)) {
- //$password = $_configuration['password_encryption'] ? api_get_encrypted_password($password) : $password;
- //$sql .= " password='".Database::escape_string($password)."',";
- $user->setPlainPassword($password);
- }
- if (!is_null($auth_source)) {
- $user->setAuthSource($auth_source);
- }
- // Exception for admins in case no status is provided in WS call...
- $t_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
- $sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id);
- $resadmin = Database::query($sqladmin);
- $is_admin = Database::num_rows($resadmin);
- if (empty($status)) {
- $status = 5;
- }
- if ($is_admin) {
- $status = 1;
- }
- if (!empty($expiration_date)) {
- $expiration_date = new DateTime($expiration_date);
- }
- $user
- ->setEmail($email)
- ->setStatus($status)
- ->setOfficialCode($official_code)
- ->setPhone($phone)
- ->setExpirationDate($expiration_date)
- ->setHrDeptId($hr_dept_id)
- ->setActive(true);
- if (!is_null($creator_id)) {
- $user->setCreatorId($creator_id);
- //$sql .= ", creator_id='".Database::escape_string($creator_id)."'";
- }
- $userManager->updateUser($user, true);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $user_id,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = $user->getId();
- continue;
- }
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_value' => $orig_user_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSEditUser function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editUser',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSEditUser', // method name
- array('editUser' => 'tns:editUser'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditUser', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a user from wiener' // documentation
- );
- // Define the method WSEditUser
- function WSEditUser($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userManager = UserManager::getManager();
- $userRepository = UserManager::getRepository();
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- $original_user_id_value = $params['original_user_id_value'];
- $original_user_id_name = $params['original_user_id_name'];
- $firstname = $params['firstname'];
- $lastname = $params['lastname'];
- $username = $params['username'];
- $password = null;
- $auth_source = null;
- $email = $params['email'];
- $status = $params['status'];
- $official_code = '';
- $phone = $params['phone'];
- $picture_uri = '';
- $expiration_date = $params['expiration_date'];
- $active = 1;
- $creator_id = null;
- $hr_dept_id = 0;
- $extra = null;
- $extra_list = $params['extra'];
- if (!empty($params['password'])) {
- $password = $params['password'];
- }
- // Get user id from id wiener
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($user_id == 0) {
- return 0;
- } else {
- $sql = "SELECT user_id FROM $table_user
- WHERE user_id ='$user_id' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- return 0;
- }
- }
- // Check whether username already exits.
- $sql = "SELECT username FROM $table_user
- WHERE username = '$username' AND user_id <> '$user_id'";
- $res_un = Database::query($sql);
- $r_username = Database::fetch_row($res_un);
- if (!empty($r_username[0])) {
- return 0;
- }
- /** @var User $user */
- $user = $userRepository->find($user_id);
- if (!empty($lastname)) {
- $user->setLastname($lastname);
- //$sql .= " lastname='".Database::escape_string($lastname)."', ";
- }
- if (!empty($firstname)) {
- $user->setFirstname($firstname);
- //$sql .= " firstname='".Database::escape_string($firstname)."', ";
- }
- $user->setUsername($username);
- //$sql .= " username='".Database::escape_string($username)."',";
- if (!is_null($password)) {
- //$password = $_configuration['password_encryption'] ? api_get_encrypted_password($password) : $password;
- //$sql .= " password='".Database::escape_string($password)."',";
- $user->setPlainPassword($password);
- }
- if (!is_null($auth_source)) {
- $user->setAuthSource($auth_source);
- }
- // Exception for admins in case no status is provided in WS call...
- $t_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
- $sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id);
- $resadmin = Database::query($sqladmin);
- $is_admin = Database::num_rows($resadmin);
- if (empty($status)) {
- $status = 5;
- }
- if ($is_admin) {
- $status = 1;
- }
- if (!empty($expiration_date)) {
- $expiration_date = new DateTime($expiration_date);
- }
- $user
- ->setEmail($email)
- ->setStatus($status)
- ->setOfficialCode($official_code)
- ->setPhone($phone)
- ->setPictureUri($picture_uri)
- ->setExpirationDate($expiration_date)
- ->setHrDeptId($hr_dept_id)
- ->setActive(true);
- if (!is_null($creator_id)) {
- $user->setCreatorId($creator_id);
- //$sql .= ", creator_id='".Database::escape_string($creator_id)."'";
- }
- $userManager->updateUser($user, true);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $user_id,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- return $user_id;
- }
- /* Register WSEditUserWithPicture function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editUserWithPicture',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'picture_url' => array('name' => 'picture_url', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSEditUserWithPicture', // method name
- array('editUserWithPicture' => 'tns:editUserWithPicture'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditUserWithPicture', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a user from wiener' // documentation
- );
- // Define the method WSEditUserWithPicture
- function WSEditUserWithPicture($params)
- {
- global $_configuration;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userManager = UserManager::getManager();
- $userRepository = UserManager::getRepository();
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- $original_user_id_value = $params['original_user_id_value'];
- $original_user_id_name = $params['original_user_id_name'];
- $firstname = $params['firstname'];
- $lastname = $params['lastname'];
- $username = $params['username'];
- $password = null;
- $auth_source = null;
- $email = $params['email'];
- $expiration_date = null;
- $expirationDateStatement = '';
- $status = $params['status'];
- $phone = $params['phone'];
- $picture_url = $params['picture_url'];
- $pictureUri = '';
- $active = 1;
- $creator_id = null;
- $hr_dept_id = 0;
- $extra = null;
- $extra_list = $params['extra'];
- if (!empty($params['expiration_date'])) {
- $expiration_date = $params['expiration_date'];
- }
- if (!empty($params['password'])) {
- $password = $params['password'];
- }
- // Get user id from external id
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- // Get picture and generate uri.
- $filename = basename($picture_url);
- $tempdir = sys_get_temp_dir();
- $tempDir = api_get_path(SYS_ARCHIVE_PATH);
- // Make sure the file download was OK by checking the HTTP headers for OK
- if (strpos(get_headers($picture_url)[0], "OK")) {
- file_put_contents($tempDir . $filename, file_get_contents($picture_url));
- $pictureUri = UserManager::update_user_picture($user_id, $filename, $tempDir . $filename);
- }
- if ($user_id == 0) {
- return 0;
- } else {
- $sql = "SELECT id FROM $table_user WHERE id =$user_id AND active= 0";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- return 0;
- }
- }
- // Check whether username already exits.
- $sql = "SELECT username FROM $table_user WHERE username = '$username' AND id <> $user_id";
- $res_un = Database::query($sql);
- $r_username = Database::fetch_row($res_un);
- if (!empty($r_username[0])) {
- return 0;
- }
- /** @var User $user */
- $user = $userRepository->find($user_id);
- if (!empty($lastname)) {
- $user->setLastname($lastname);
- //$sql .= " lastname='".Database::escape_string($lastname)."', ";
- }
- if (!empty($firstname)) {
- $user->setFirstname($firstname);
- //$sql .= " firstname='".Database::escape_string($firstname)."', ";
- }
- $user->setUsername($username);
- //$sql .= " username='".Database::escape_string($username)."',";
- if (!is_null($password)) {
- //$password = $_configuration['password_encryption'] ? api_get_encrypted_password($password) : $password;
- //$sql .= " password='".Database::escape_string($password)."',";
- $user->setPlainPassword($password);
- }
- if (!is_null($auth_source)) {
- $user->setAuthSource($auth_source);
- }
- // Exception for admins in case no status is provided in WS call...
- $t_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
- $sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id);
- $resadmin = Database::query($sqladmin);
- $is_admin = Database::num_rows($resadmin);
- if (empty($status)) {
- $status = $user->getStatus();
- }
- if ($is_admin) {
- $status = 1;
- }
- if (!empty($expiration_date)) {
- $expiration_date = new DateTime($expiration_date);
- }
- $user
- ->setEmail($email)
- ->setStatus($status)
- ->setPhone($phone)
- ->setExpirationDate($expiration_date)
- ->setHrDeptId($hr_dept_id)
- ->setActive(true)
- ->setPictureUri($pictureUri);;
- if (!is_null($creator_id)) {
- $user->setCreatorId($creator_id);
- //$sql .= ", creator_id='".Database::escape_string($creator_id)."'";
- }
- $userManager->updateUser($user, true);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into user_field_value table.
- UserManager::update_extra_field_value(
- $user_id,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- return $user_id;
- }
- /* Register WSEditUsersPasswordCrypted function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editUsersPasswordCryptedParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'editUsersPasswordCryptedParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editUsersPasswordCryptedParams[]')),
- 'tns:editUsersPasswordCryptedParams'
- );
- $server->wsdl->addComplexType(
- 'editUsersPasswordCrypted',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'users' => array('name' => 'users', 'type' => 'tns:editUsersPasswordCryptedParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_editUsersPasswordCrypted',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_editUsersPasswordCrypted',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editUsersPasswordCrypted[]')),
- 'tns:result_editUsersPasswordCrypted'
- );
- // Register the method to expose
- $server->register('WSEditUsersPasswordCrypted', // method name
- array('editUsersPasswordCrypted' => 'tns:editUsersPasswordCrypted'), // input parameters
- array('return' => 'tns:results_editUsersPasswordCrypted'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditUsersPasswordCrypted', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a user' // documentation
- );
- // Define the method WSEditUsersPasswordCrypted
- function WSEditUsersPasswordCrypted($params) {
- global $_configuration;
- if(!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- // get user id from id of remote system
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- $users_params = $params['users'];
- $results = array();
- $orig_user_id_value = array();
- foreach ($users_params as $user_param) {
- $original_user_id_value = $user_param['original_user_id_value'];
- $original_user_id_name = $user_param['original_user_id_name'];
- $orig_user_id_value[] = $original_user_id_value;
- $firstname = $user_param['firstname'];
- $lastname = $user_param['lastname'];
- $username = $user_param['username'];
- $password = null;
- $auth_source = null;
- $email = $user_param['email'];
- $status = $user_param['status'];
- $official_code = '';
- $phone = $user_param['phone'];
- $picture_uri = '';
- $expiration_date = $user_param['expiration_date'];
- $active = 1;
- $creator_id = null;
- $hr_dept_id = 0;
- $extra = null;
- $extra_list = $user_param['extra'];
- if (!empty($user_param['password']) && !empty($user_param['encrypt_method'])) {
- $password = $user_param['password'];
- $encrypt_method = $user_param['encrypt_method'];
- if ($_configuration['password_encryption'] === $encrypt_method ) {
- if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- $results[] = $msg;
- continue;
- } else if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- $results[] = $msg;
- continue;
- }
- } else {
- $msg = "This encryption $encrypt_method is not configured";
- $results[] = $msg;
- continue;
- }
- } elseif (!empty($user_param['password']) && empty($user_param['encrypt_method'])){
- $msg = "If password is not empty the encrypt_method param is required ";
- $results[] = $msg;
- continue;
- } elseif (empty($user_param['password']) && !empty($user_param['encrypt_method'])){
- $msg = "If encrypt_method is not empty the password param is required ";
- $results[] = $msg;
- continue;
- }
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($user_id == 0) {
- $results[] = 0; // Original_user_id_value doesn't exist.
- continue;
- } else {
- $sql = "SELECT user_id FROM $table_user
- WHERE user_id ='$user_id' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- $results[] = 0; // user_id is not active
- continue;
- }
- }
- // Check if username already exits.
- $sql = "SELECT username FROM $table_user
- WHERE username ='$username' AND user_id <> '$user_id'";
- $res_un = Database::query($sql);
- $r_username = Database::fetch_row($res_un);
- if (!empty($r_username[0])) {
- $results[] = 0;
- continue; // username already exits
- }
- $sql = "UPDATE $table_user SET ";
- if (!empty($lastname)) {
- $sql .= " lastname='".Database::escape_string($lastname)."', ";
- }
- if (!empty($firstname)) {
- $sql .= " firstname='".Database::escape_string($firstname)."', ";
- }
- $sql .= " username='".Database::escape_string($username)."',";
- if (!is_null($password)) {
- $sql .= " password='".Database::escape_string($password)."',";
- }
- if (!is_null($auth_source)) {
- $sql .= " auth_source='".Database::escape_string($auth_source)."',";
- }
- // Exception for admins in case no status is provided in WS call...
- $t_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
- $sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id);
- $resadmin = Database::query($sqladmin);
- $is_admin = Database::num_rows($resadmin);
- if (empty($status)) {
- $status = 5;
- }
- if ($is_admin) {
- $status = 1;
- }
- $sql .= "
- email='".Database::escape_string($email)."',
- status='".Database::escape_string($status)."',
- official_code='".Database::escape_string($official_code)."',
- phone='".Database::escape_string($phone)."',
- picture_uri='".Database::escape_string($picture_uri)."',
- expiration_date='".Database::escape_string($expiration_date)."',
- active='".Database::escape_string($active)."',
- hr_dept_id=".intval($hr_dept_id);
- if (!is_null($creator_id)) {
- $sql .= ", creator_id='".Database::escape_string($creator_id)."'";
- }
- $sql .= " WHERE user_id='$user_id'";
- $return = @Database::query($sql);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into user_field_value table.
- $res = UserManager::update_extra_field_value(
- $user_id,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = $return;
- continue;
- } //end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_value' => $orig_user_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSEditUserPasswordCrypted function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editUserPasswordCrypted',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'password' => array('name' => 'password', 'type' => 'xsd:string'),
- 'encrypt_method' => array('name' => 'encrypt_method', 'type' => 'xsd:string'),
- 'email' => array('name' => 'email', 'type' => 'xsd:string'),
- 'status' => array('name' => 'status', 'type' => 'xsd:string'),
- 'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
- 'expiration_date' => array('name' => 'expiration_date', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSEditUserPasswordCrypted', // method name
- array('editUserPasswordCrypted' => 'tns:editUserPasswordCrypted'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditUserPasswordCrypted', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a user' // documentation
- );
- // Define the method WSEditUserPasswordCrypted
- function WSEditUserPasswordCrypted($params)
- {
- global $_configuration;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $table_user = Database::get_main_table(TABLE_MAIN_USER);
- $original_user_id_value = $params['original_user_id_value'];
- $original_user_id_name = $params['original_user_id_name'];
- $firstname = $params['firstname'];
- $lastname = $params['lastname'];
- $username = $params['username'];
- $password = null;
- $auth_source = null;
- $email = $params['email'];
- $status = $params['status'];
- $official_code = '';
- $phone = $params['phone'];
- $picture_uri = '';
- $expiration_date = $params['expiration_date'];
- $active = 1;
- $creator_id = null;
- $hr_dept_id = 0;
- $extra = null;
- $extra_list = $params['extra'];
- if (!empty($params['password']) && !empty($params['encrypt_method'])) {
- $password = $params['password'];
- $encrypt_method = $params['encrypt_method'];
- if ($_configuration['password_encryption'] === $encrypt_method ) {
- if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- return $msg;
- } else if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
- $msg = "Encryption $encrypt_method is invalid";
- return $msg;
- }
- } else {
- $msg = "This encryption $encrypt_method is not configured";
- return $msg;
- }
- } elseif (!empty($params['password']) && empty($params['encrypt_method'])) {
- $msg = "If password is not empty the encrypt_method param is required ";
- return $msg;
- } elseif (empty($params['password']) && !empty($params['encrypt_method'])) {
- $msg = "If encrypt_method is not empty the password param is required ";
- return $msg;
- }
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_value,
- $original_user_id_name
- );
- if ($user_id == 0) {
- return 0;
- } else {
- $sql = "SELECT user_id FROM $table_user
- WHERE user_id ='$user_id' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- return 0;
- }
- }
- // Check whether username already exits.
- $sql = "SELECT username FROM $table_user
- WHERE username ='$username' AND user_id <> '$user_id'";
- $res_un = Database::query($sql);
- $r_username = Database::fetch_row($res_un);
- if (!empty($r_username[0])) {
- return 0;
- }
- // Edit lastname and firstname only if not empty
- $sql = "UPDATE $table_user SET ";
- if (!empty($lastname)) {
- $sql .= " lastname='".Database::escape_string($lastname)."', ";
- }
- if (!empty($firstname)) {
- $sql .= " firstname='".Database::escape_string($firstname)."', ";
- }
- $sql .= " username='".Database::escape_string($username)."',";
- if (!is_null($password)) {
- $sql .= " password='".Database::escape_string($password)."',";
- }
- if (!is_null($auth_source)) {
- $sql .= " auth_source='".Database::escape_string($auth_source)."',";
- }
- // Exception for admins in case no status is provided in WS call...
- $t_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
- $sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id);
- $resadmin = Database::query($sqladmin);
- $is_admin = Database::num_rows($resadmin);
- if (empty($status)) {
- $status = 5;
- }
- if ($is_admin) {
- $status = 1;
- }
- $sql .= "
- email='".Database::escape_string($email)."',
- status='".Database::escape_string($status)."',
- official_code='".Database::escape_string($official_code)."',
- phone='".Database::escape_string($phone)."',
- picture_uri='".Database::escape_string($picture_uri)."',
- expiration_date='".Database::escape_string($expiration_date)."',
- active='".Database::escape_string($active)."',
- hr_dept_id=".intval($hr_dept_id);
- if (!is_null($creator_id)) {
- $sql .= ", creator_id='".Database::escape_string($creator_id)."'";
- }
- $sql .= " WHERE user_id='$user_id'";
- $return = @Database::query($sql);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // save the external system's id into user_field_value table'
- $res = UserManager::update_extra_field_value(
- $user_id,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- return $return;
- }
- /** WSDeleteUsers **/
- $server->wsdl->addComplexType(
- 'user_id',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'user_ids_array',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:user_id[]')),'tns:user_id'
- );
- $server->wsdl->addComplexType(
- 'user_ids',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'ids' => array('name' => 'user_ids', 'type' => 'tns:user_ids_array'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- function WSHelperActionOnUsers($params, $type) {
- if(!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $original_user_ids = $params['ids'];
- foreach($original_user_ids as $original_user_id) {
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id['original_user_id_value'],
- $original_user_id['original_user_id_name']
- );
- if($user_id > 0) {
- if($type == "delete") {
- UserManager::delete_user($user_id);
- } else if($type == "disable") {
- UserManager::disable($user_id);
- } else if($type == "enable") {
- UserManager::enable($user_id);
- }
- }
- }
- }
- $server->register('WSDeleteUsers', // method name
- array('user_ids' => 'tns:user_ids'), // input parameters
- array(), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSDeleteUsers', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'Deletes users provided as parameters from the system' // documentation
- );
- function WSDeleteUsers($params) {
- WSHelperActionOnUsers($params, "delete");
- }
- /** WSDisableUsers **/
- $server->register('WSDisableUsers', // method name
- array('user_ids' => 'tns:user_ids'), // input parameters
- array(), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSDisableUsers', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'Disables users provided as parameters from the system' // documentation
- );
- function WSDisableUsers($params) {
- WSHelperActionOnUsers($params, "disable");
- }
- /** WSEnableUsers **/
- $server->register('WSEnableUsers', // method name
- array('user_ids' => 'tns:user_ids'), // input parameters
- array(), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEnableUsers', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'Enables users provided as parameters' // documentation
- );
- function WSEnableUsers($params) {
- WSHelperActionOnUsers($params, "enable");
- }
- /* Register WSCreateCourse function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'course_id',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'createCourseParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'title' => array('name' => 'title', 'type' => 'xsd:string'),
- 'category_code' => array('name' => 'category_code', 'type' => 'xsd:string'),
- 'wanted_code' => array('name' => 'wanted_code', 'type' => 'xsd:string'),
- 'tutor_name' => array('name' => 'tutor_name', 'type' => 'xsd:string'),
- 'course_language' => array('name' => 'course_language', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'createCourseParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:createCourseParams[]')),'tns:createCourseParams'
- );
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'createCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'courses' => array('name' => 'courses', 'type' => 'tns:createCourseParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_createCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_createCourse',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createCourse[]')),
- 'tns:result_createCourse'
- );
- // Register the method to expose
- $server->register('WSCreateCourse', // method name
- array('createCourse' => 'tns:createCourse'), // input parameters
- array('return' => 'tns:results_createCourse'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateCourse', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds a course' // documentation
- );
- // Define the method WSCreateCourse
- function WSCreateCourse($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
- $courses_params = $params['courses'];
- $results = array();
- $orig_course_id_value = array();
- foreach ($courses_params as $course_param) {
- $title = $course_param['title'];
- $category_code = $course_param['category_code'];
- $wanted_code = $course_param['wanted_code'];
- $tutor_name = $course_param['tutor_name'];
- $course_language = 'english'; // TODO: A hard-coded value.
- $original_course_id_name = $course_param['original_course_id_name'];
- $original_course_id_value = $course_param['original_course_id_value'];
- $orig_course_id_value[] = $course_param['original_course_id_value'];
- $visibility = null;
- if ($course_param['visibility'] &&
- $course_param['visibility'] >= 0 &&
- $course_param['visibility'] <= 3
- ) {
- $visibility = $course_param['visibility'];
- }
- $extra_list = $course_param['extra'];
- // Check whether exits $x_course_code into user_field_values table.
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $course_param['original_course_id_value'],
- $course_param['original_course_id_name']
- );
- if (!empty($courseInfo)) {
- if ($courseInfo['visibility'] != 0) {
- $sql = "UPDATE $table_course SET
- course_language='".Database::escape_string($course_language)."',
- title='".Database::escape_string($title)."',
- category_code='".Database::escape_string($category_code)."',
- tutor_name='".Database::escape_string($tutor_name)."',
- visual_code='".Database::escape_string($wanted_code)."'";
- if($visibility !== null) {
- $sql .= ", visibility = '$visibility' ";
- }
- $sql .= " WHERE id='".$courseInfo['real_id']."'";
- Database::query($sql);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into course_field_value table.
- CourseManager::update_course_extra_field_value(
- $courseInfo['code'],
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = $courseInfo['code'];
- continue;
- } else {
- $results[] = 0;
- continue; // Original course id already exits.
- }
- }
- if (!empty($course_param['course_language'])) {
- $course_language = $course_param['course_language'];
- }
- // Set default values
- if (isset($_user['language']) && $_user['language'] != '') {
- $values['course_language'] = $_user['language'];
- } else {
- $values['course_language'] = api_get_setting('platformLanguage');
- }
- $values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastName'], null, null, $values['course_language']);
- $params = array();
- $params['title'] = $title;
- $params['wanted_code'] = $wanted_code;
- $params['category_code'] = $category_code;
- $params['tutor_name'] = $tutor_name;
- $params['course_language'] = $course_language;
- $params['user_id'] = api_get_user_id();
- $params['visibility'] = $visibility;
- $course_info = CourseManager::create_course($params);
- if (!empty($course_info)) {
- $course_code = $course_info['code'];
- // Save new field label into course_field table
- CourseManager::create_course_extra_field(
- $original_course_id_name,
- 1,
- $original_course_id_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- CourseManager::update_course_extra_field_value(
- $course_code,
- $original_course_id_name,
- $original_course_id_value
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save new fieldlabel into course_field table.
- CourseManager::create_course_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name,
- ''
- );
- // Save the external system's id into course_field_value table.
- CourseManager::update_course_extra_field_value(
- $course_code,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = $course_code;
- } else {
- $results[] = 0;
- }
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_value' => $orig_course_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSCreateCourseByTitle function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'createCourseByTitleParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'title' => array('name' => 'title', 'type' => 'xsd:string'),
- 'tutor_name' => array('name' => 'tutor_name', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'createCourseByTitleParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:createCourseByTitleParams[]')),
- 'tns:createCourseByTitleParams'
- );
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'createCourseByTitle',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'courses' => array('name' => 'courses', 'type' => 'tns:createCourseByTitleParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_createCourseByTitle',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_createCourseByTitle',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createCourseByTitle[]')),
- 'tns:result_createCourseByTitle'
- );
- // Register the method to expose
- $server->register('WSCreateCourseByTitle', // method name
- array('createCourseByTitle' => 'tns:createCourseByTitle'), // input parameters
- array('return' => 'tns:results_createCourseByTitle'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateCourseByTitle', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds a course by title' // documentation
- );
- // Define the method WSCreateCourseByTitle
- function WSCreateCourseByTitle($params)
- {
- global $firstExpirationDelay, $_configuration;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $courses_params = $params['courses'];
- $results = array();
- $orig_course_id_value = array();
- foreach ($courses_params as $course_param) {
- $title = $course_param['title'];
- $category_code = 'LANG'; // TODO: A hard-coded value.
- $wanted_code = '';
- $tutor_firstname = api_get_setting('administratorName');
- $tutor_lastname = api_get_setting('administratorSurname');
- $course_language = 'spanish'; // TODO: Incorrect default value, it should 'english'.
- if (!empty($course_param['course_language'])) {
- $course_language = $course_param['course_language'];
- }
- $tutor_name = api_get_person_name($tutor_firstname, $tutor_lastname, null, null, $course_language);
- if (!empty($course_param['tutor_name'])) {
- $tutor_name = $course_param['tutor_name'];
- }
- $original_course_id_name = $course_param['original_course_id_name'];
- $original_course_id_value = $course_param['original_course_id_value'];
- $orig_course_id_value[] = $course_param['original_course_id_value'];
- $extra_list = $course_param['extra'];
- // Ensure the database prefix + database name do not get over 40 characters
- $maxlength = 40;
- if (empty($wanted_code)) {
- $wanted_code = CourseManager::generate_course_code(substr($title, 0, $maxlength));
- }
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id_value,
- $original_course_id_name
- );
- if (!empty($courseInfo)) {
- if ($courseInfo['visibility'] != 0) {
- $sql = "UPDATE $table_course SET
- course_language='".Database::escape_string($course_language)."',
- title='".Database::escape_string($title)."',
- category_code='".Database::escape_string($category_code)."',
- tutor_name='".Database::escape_string($tutor_name)."',
- visual_code='".Database::escape_string($wanted_code)."',
- visibility = '3'
- WHERE id ='".$courseInfo['real_id']."'";
- Database::query($sql);
- $results[] = $courseInfo['real_id'];
- continue;
- } else {
- $results[] = 0;
- continue;
- }
- }
- // Set default values.
- if (isset($_user['language']) && $_user['language'] != '') {
- $values['course_language'] = $_user['language'];
- } else {
- $values['course_language'] = api_get_setting('platformLanguage');
- }
- $values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastName'], null, null, $values['course_language']);
- $keys = AddCourse::define_course_keys($wanted_code, '', $_configuration['db_prefix']);
- $sql_check = sprintf('SELECT * FROM '.$table_course.' WHERE visual_code = "%s"', Database :: escape_string($wanted_code));
- $result_check = Database::query($sql_check); // I don't know why this api function doesn't work...
- if (Database::num_rows($result_check) < 1) {
- $params = array();
- $params['title'] = $title;
- $params['wanted_code'] = $wanted_code;
- $params['category_code'] = $category_code;
- $params['tutor_name'] = $tutor_name;
- $params['course_language'] = $course_language;
- $params['user_id'] = api_get_user_id();
- //$params['visibility'] = $visibility;
- $course_info = CourseManager::create_course($params);
- if (!empty($course_info)) {
- $course_code = $course_info['code'];
- // Save new fieldlabel into course_field table.
- CourseManager::create_course_extra_field(
- $original_course_id_name,
- 1,
- $original_course_id_name,
- ''
- );
- // Save the external system's id into user_field_value table.
- CourseManager::update_course_extra_field_value(
- $course_code,
- $original_course_id_name,
- $original_course_id_value
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save new fieldlabel into course_field table.
- CourseManager::create_course_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name,
- ''
- );
- // Save the external system's id into course_field_value table.
- CourseManager::update_course_extra_field_value(
- $course_code,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- }
- $results[] = $course_code;
- continue;
- } else {
- $results[] = 0;
- continue;
- }
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_value' => $orig_course_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSEditCourse function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editCourseParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'tutor_id' => array('name' => 'tutor_id', 'type' => 'xsd:string'),
- 'title' => array('name' => 'title', 'type' => 'xsd:string'),
- 'category_code' => array('name' => 'category_code', 'type' => 'xsd:string'),
- 'department_name' => array('name' => 'department_name', 'type' => 'xsd:string'),
- 'department_url' => array('name' => 'department_url', 'type' => 'xsd:string'),
- 'course_language' => array('name' => 'course_language', 'type' => 'xsd:string'),
- 'visibility' => array('name' => 'visibility', 'type' => 'xsd:string'),
- 'subscribe' => array('name' => 'subscribe', 'type' => 'xsd:string'),
- 'unsubscribe' => array('name' => 'unsubscribe', 'type' => 'xsd:string'),
- 'visual_code' => array('name' => 'visual_code', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'editCourseParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editCourseParams[]')),
- 'tns:editCourseParams'
- );
- $server->wsdl->addComplexType(
- 'editCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'courses' => array('name' => 'courses', 'type' => 'tns:editCourseParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_editCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_editCourse',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editCourse[]')),
- 'tns:result_editCourse'
- );
- // Register the method to expose
- $server->register('WSEditCourse', // method name
- array('editCourse' => 'tns:editCourse'), // input parameters
- array('return' => 'tns:results_editCourse'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditCourse', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a course' // documentation
- );
- // Define the method WSEditCourse
- function WSEditCourse($params){
- global $_configuration;
- if(!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $courses_params = $params['courses'];
- $results = array();
- $orig_course_id_value = array();
- foreach ($courses_params as $course_param) {
- $tutor_id = $course_param['tutor_id'];
- $title = $course_param['title'];
- $category_code = $course_param['category_code'];
- $department_name = $course_param['department_name'];
- $department_url = $course_param['department_url'];
- $course_language = $course_param['course_language'];
- $visibility = $course_param['visibility'];
- $subscribe = $course_param['subscribe'];
- $unsubscribe = $course_param['unsubscribe'];
- $visual_code = $course_param['visual_code'];
- $original_course_id_name = $course_param['original_course_id_name'];
- $original_course_id_value = $course_param['original_course_id_value'];
- $orig_course_id_value[] = $original_course_id_value;
- $extra_list = $course_param['extra'];
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id_value,
- $original_course_id_name
- );
- if (empty($courseInfo)) {
- $results[] = 0; // Original_course_id_value doesn't exist.
- continue;
- }
- $course_code = $courseInfo['code'];
- $courseId = $courseInfo['real_id'];
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT concat(lastname,'',firstname) as tutor_name
- FROM $table_user WHERE status='1' AND user_id = '$tutor_id'
- ORDER BY lastname,firstname";
- $res = Database::query($sql);
- $tutor_name = Database::fetch_row($res);
- $dbnamelength = strlen($_configuration['db_prefix']);
- $maxlength = 40 - $dbnamelength;
- if (empty($visual_code)) {
- $visual_code = CourseManager::generate_course_code(substr($title, 0, $maxlength));
- }
- $disk_quota = '50000'; // TODO: A hard-coded value.
- $tutor_name = $tutor_name[0];
- $sql = "UPDATE $course_table SET
- course_language='".Database::escape_string($course_language)."',
- title='".Database::escape_string($title)."',
- category_code='".Database::escape_string($category_code)."',
- tutor_name='".Database::escape_string($tutor_name)."',
- visual_code='".Database::escape_string($visual_code)."',
- department_name='".Database::escape_string($department_name)."',
- department_url='".Database::escape_string($department_url)."',
- disk_quota='".Database::escape_string($disk_quota)."',
- visibility = '".Database::escape_string($visibility)."',
- subscribe = '".Database::escape_string($subscribe)."',
- unsubscribe='".Database::escape_string($unsubscribe)."'
- WHERE id ='".Database::escape_string($courseId)."'";
- $res = Database::query($sql);
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into course_field_value table.
- $res = CourseManager::update_course_extra_field_value(
- $course_code,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- if ($res) {
- $results[] = 1;
- continue;
- } else {
- $results[] = 0;
- continue;
- }
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_value' => $orig_course_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSCourseDescription function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'courseDescription',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'fields_course_desc',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'course_desc_id' => array('name' => 'course_desc_id', 'type' => 'xsd:string'),
- 'course_desc_default_title' => array('name' => 'course_desc_default_title', 'type' => 'xsd:string'),
- 'course_desc_title' => array('name' => 'course_desc_title', 'type' => 'xsd:string'),
- 'course_desc_content' => array('name' => 'course_desc_content', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'fields_course_desc_list',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:fields_course_desc[]')),
- 'tns:fields_course_desc'
- );
- // Register the method to expose
- $server->register('WSCourseDescription', // method name
- array('courseDescription' => 'tns:courseDescription'), // input parameters
- array('return' => 'tns:fields_course_desc_list'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCourseDescription', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a course description' // documentation
- );
- // Define the method WSCourseDescription
- function WSCourseDescription($params)
- {
- global $_course;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $array_course_desc_id = array();
- $array_course__desc_default_title = array();
- $array_course_desc_title = array();
- $array_course_desc_content = array();
- $original_course_id_name = $params['original_course_id_name'];
- $original_course_id_value = $params['original_course_id_value'];
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id_value,
- $original_course_id_name
- );
- if (empty($courseInfo) || (isset($courseInfo) && $courseInfo['visibility'] == 0)) {
- return 0; // Original_course_id_value doesn't exist.
- }
- $t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
- $sql = "SELECT * FROM $t_course_desc WHERE c_id = {$courseInfo['real_id']} ";
- $result = Database::query($sql);
- $default_titles = array(
- get_lang('GeneralDescription'),
- get_lang('Objectives'),
- get_lang('Topics'),
- get_lang('Methodology'),
- get_lang('CourseMaterial'),
- get_lang('HumanAndTechnicalResources'),
- get_lang('Assessment'),
- get_lang('AddCategory')
- );
- // TODO: Hard-coded Spanish texts.
- //$default_titles = array('Descripcion general', 'Objetivos', 'Contenidos', 'Metodologia', 'Materiales', 'Recursos humanos y tecnicos', 'Evaluacion', 'Apartado');
- for ($x = 1; $x < 9; $x++) {
- $array_course_desc_id[$x] = $x;
- $array_course_desc_default_title[$x] = $default_titles[$x - 1];
- $array_course_desc_title[$x] = '';
- $array_course_desc_content[$x] = '';
- }
- while ($row = Database::fetch_array($result)) {
- $ind = (int)$row['id'];
- $array_course_desc_title[$ind] = $row['title'];
- $array_course_desc_content[$ind] = $row['content'];
- }
- $count_results = count($default_titles);
- $output = array();
- for($i = 1; $i <= $count_results; $i++) {
- $output[] = array(
- 'course_desc_id' => $array_course_desc_id[$i],
- 'course_desc_default_title' => $array_course_desc_default_title[$i],
- 'course_desc_title' => $array_course_desc_title[$i],
- 'course_desc_content' => $array_course_desc_content[$i]
- );
- }
- return $output;
- }
- /* Register WSEditCourseDescription function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editCourseDescriptionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'course_desc_id' => array('name' => 'course_desc_id', 'type' => 'xsd:string'),
- 'course_desc_title' => array('name' => 'course_desc_title', 'type' => 'xsd:string'),
- 'course_desc_content' => array('name' => 'course_desc_content', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'editCourseDescriptionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editCourseDescriptionParams[]')),
- 'tns:editCourseDescriptionParams'
- );
- $server->wsdl->addComplexType(
- 'editCourseDescription',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'course_desc' => array('name' => 'course_desc', 'type' => 'tns:editCourseDescriptionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_editCourseDescription',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_editCourseDescription',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editCourseDescription[]')),
- 'tns:result_editCourseDescription'
- );
- // Register the method to expose
- $server->register('WSEditCourseDescription', // method name
- array('editCourseDescription' => 'tns:editCourseDescription'), // input parameters
- array('return' => 'tns:results_editCourseDescription'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditCourseDescription', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a course description' // documentation
- );
- // Define the method WSEditCourseDescription
- function WSEditCourseDescription($params) {
- global $_course;
- if (!WSHelperVerifyKey($params)) {
- return -1;
- }
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $courses_params = $params['course_desc'];
- $results = array();
- $orig_course_id_value = array();
- foreach ($courses_params as $course_param) {
- $original_course_id_name = $course_param['original_course_id_name'];
- $original_course_id_value = $course_param['original_course_id_value'];
- $course_desc_id = $course_param['course_desc_id'];
- $course_desc_title = $course_param['course_desc_title'];
- $course_desc_content = $course_param['course_desc_content'];
- $orig_course_id_value[] = $original_course_id_value;
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id_value,
- $original_course_id_name
- );
- if (empty($courseInfo) || (isset($courseInfo) && $courseInfo['visibility'] == 0)) {
- $results[] = 0;
- continue; // Original_course_id_value doesn't exist.
- }
- $t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
- $course_desc_id = Database::escape_string($course_desc_id);
- $course_desc_title = Database::escape_string($course_desc_title);
- $course_desc_content = Database::escape_string($course_desc_content);
- $course_desc_id = (int)$course_desc_id;
- if ($course_desc_id > 8 && $course_desc_id < 1) {
- $results[] = 0; // course_desc_id invalid.
- continue;
- }
- // Check whether data already exits into course_description table.
- $sql_check_id = "SELECT * FROM $t_course_desc
- WHERE c_id = {$courseInfo['real_id']} AND id ='$course_desc_id'";
- $res_check_id = Database::query($sql_check_id);
- if (Database::num_rows($res_check_id) > 0) {
- $sql = "UPDATE $t_course_desc SET
- title = '$course_desc_title',
- content = '$course_desc_content'
- WHERE
- c_id = {$courseInfo['real_id']} AND
- id = '".$course_desc_id."'";
- Database::query($sql);
- } else {
- $sql = "INSERT IGNORE INTO $t_course_desc SET
- c_id = {$courseInfo['real_id']},
- id = '".$course_desc_id."',
- title = '$course_desc_title',
- content = '$course_desc_content'";
- Database::query($sql);
- }
- $results[] = 1;
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_value' => $orig_course_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSDeleteCourse function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'deleteCourseParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'deleteCourseParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:deleteCourseParams[]')),
- 'tns:deleteCourseParams'
- );
- // Register the data structures used by the service.
- $server->wsdl->addComplexType(
- 'deleteCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'courses' => array('name' => 'courses', 'type' => 'tns:deleteCourseParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array.
- $server->wsdl->addComplexType(
- 'result_deleteCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_deleteCourse',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_deleteCourse[]')),
- 'tns:result_deleteCourse'
- );
- $server->register('WSDeleteCourse', // method name
- array('deleteCourse' => 'tns:deleteCourse'), // input parameters
- array('return' => 'tns:results_deleteCourse'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSDeleteCourse', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service deletes a course ' // documentation
- );
- // Define the method WSDeleteCourse
- function WSDeleteCourse($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
- $courses_params = $params['courses'];
- $results = array();
- $orig_course_id_value = array();
- foreach ($courses_params as $course_param) {
- $original_course_id_value = $course_param['original_course_id_value'];
- $original_course_id_name = $course_param['original_course_id_name'];
- $orig_course_id_value[] = $original_course_id_value;
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id_value,
- $original_course_id_name
- );
- if (empty($courseInfo) || (isset($courseInfo) && $courseInfo['visibility'] == 0)) {
- $results[] = 0;
- continue; // Original_course_id_value doesn't exist.
- }
- $courseId = $courseInfo['real_id'];
- $sql = "UPDATE $table_course SET visibility = '0' WHERE id = '$courseId'";
- $return = Database::query($sql);
- $results[] = $return;
- }
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_value' => $orig_course_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSCreateSession function */
- // Register data structures used by the service.
- $server->wsdl->addComplexType(
- 'createSessionParam',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'name' => array('name' => 'name', 'type' => 'xsd:string'),
- 'year_start' => array('name' => 'year_start', 'type' => 'xsd:string'),
- 'month_start' => array('name' => 'month_start', 'type' => 'xsd:string'),
- 'day_start' => array('name' => 'day_start', 'type' => 'xsd:string'),
- 'year_end' => array('name' => 'year_end', 'type' => 'xsd:string'),
- 'month_end' => array('name' => 'month_end', 'type' => 'xsd:string'),
- 'day_end' => array('name' => 'day_end', 'type' => 'xsd:string'),
- 'nb_days_access_before' => array('name' => 'nb_days_access_before', 'type' => 'xsd:string'),
- 'nb_days_access_after' => array('name' => 'nb_days_access_after', 'type' => 'xsd:string'),
- 'nolimit' => array('name' => 'nolimit', 'type' => 'xsd:string'),
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'createSessionParamList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:createSessionParam[]')),
- 'tns:createSessionParam'
- );
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'createSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'sessions' => array('name' => 'sessions', 'type' => 'tns:createSessionParamList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_createSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_createSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createSession[]')),
- 'tns:result_createSession'
- );
- // Register the method to expose
- $server->register('WSCreateSession', // method name
- array('createSession' => 'tns:createSession'), // input parameters
- array('return' => 'tns:results_createSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a session' // documentation
- );
- // define the method WSCreateSession
- function WSCreateSession($params)
- {
- global $_user;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $sessions_params = $params['sessions'];
- $results = array();
- $orig_session_id_value = array();
- foreach ($sessions_params as $session_param) {
- $name = trim($session_param['name']);
- $year_start = intval($session_param['year_start']);
- $month_start = intval($session_param['month_start']);
- $day_start = intval($session_param['day_start']);
- $year_end = intval($session_param['year_end']);
- $month_end = intval($session_param['month_end']);
- $day_end = intval($session_param['day_end']);
- $nb_days_access_before = intval($session_param['nb_days_access_before']);
- $nb_days_access_after = intval($session_param['nb_days_access_after']);
- $id_coach = $session_param['user_id'];
- $nolimit = $session_param['nolimit'];
- $original_session_id_name = $session_param['original_session_id_name'];
- $original_session_id_value = $session_param['original_session_id_value'];
- $orig_session_id_value[] = $session_param['original_session_id_value'];
- $extra_list = $session_param['extra'];
- $sessionId = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($sessionId)) {
- $results[] = 0;
- continue;
- }
- if (empty($nolimit)){
- $date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start) . ' 00:00:00';
- $date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end) . ' 23:59:59';
- } else {
- $date_start = "";
- $date_end = "";
- }
- if (empty($name)) {
- $results[] = 0;
- continue;
- } elseif (empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start, $day_start, $year_start))) {
- $results[] = 0;
- continue;
- } elseif (empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) {
- $results[] = 0;
- continue;
- } elseif (empty($nolimit) && $date_start >= $date_end) {
- $results[] = 0;
- continue;
- } else {
- $rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".addslashes($name)."'");
- if (Database::num_rows($rs)) {
- $results[] = 0;
- continue;
- } else {
- $startDate = new DateTime($date_start);
- $endDate = new DateTime($date_end);
- $diffStart = new DateInterval($nb_days_access_before);
- $diffEnd = new DateInterval($nb_days_access_after);
- $coachStartDate = $startDate->sub($diffStart);
- $coachEndDate = $endDate->add($diffEnd);
- $id_session = SessionManager::create_session(
- $name,
- $date_start,
- $date_end,
- $date_start,
- $date_end,
- $coachStartDate->format('Y-m-d H:i:s'),
- $coachEndDate->format('Y-m-d H:i:s'),
- $id_coach,
- 0,
- 0,
- false,
- null,
- null,
- 0,
- array(),
- $_user['user_id']
- );
- // Save new fieldlabel into course_field table.
- $field_id = SessionManager::create_session_extra_field(
- $original_session_id_name,
- 1,
- $original_session_id_name
- );
- // Save the external system's id into user_field_value table.
- $res = SessionManager::update_session_extra_field_value(
- $id_session,
- $original_session_id_name,
- $original_session_id_value
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save new fieldlabel into course_field table.
- $field_id = SessionManager::create_session_extra_field(
- $extra_field_name,
- 1,
- $extra_field_name
- );
- // Save the external system's id into course_field_value table.
- $res = SessionManager::update_session_extra_field_value(
- $id_session,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = $id_session;
- continue;
- }
- }
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSEditSession function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'editSessionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'name' => array('name' => 'name', 'type' => 'xsd:string'),
- 'year_start' => array('name' => 'year_start', 'type' => 'xsd:string'),
- 'month_start' => array('name' => 'month_start', 'type' => 'xsd:string'),
- 'day_start' => array('name' => 'day_start', 'type' => 'xsd:string'),
- 'year_end' => array('name' => 'year_end', 'type' => 'xsd:string'),
- 'month_end' => array('name' => 'month_end', 'type' => 'xsd:string'),
- 'day_end' => array('name' => 'day_end', 'type' => 'xsd:string'),
- 'nb_days_access_before' => array('name' => 'nb_days_access_before', 'type' => 'xsd:string'),
- 'nb_days_access_after' => array('name' => 'nb_days_access_after', 'type' => 'xsd:string'),
- 'nolimit' => array('name' => 'nolimit', 'type' => 'xsd:string'),
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
- )
- );
- $server->wsdl->addComplexType(
- 'editSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editSessionParams[]')),
- 'tns:editSessionParams'
- );
- $server->wsdl->addComplexType(
- 'editSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'sessions' => array('name' => 'sessions', 'type' => 'tns:editSessionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_editSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_editSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editSession[]')),
- 'tns:result_editSession'
- );
- // Register the method to expose
- $server->register('WSEditSession', // method name
- array('editSession' => 'tns:editSession'), // input parameters
- array('return' => 'tns:results_editSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSEditSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service edits a session' // documentation
- );
- // define the method WSEditSession
- function WSEditSession($params)
- {
- global $_user;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $sessions_params = $params['sessions'];
- $results = array();
- $orig_session_id_value = array();
- foreach ($sessions_params as $session_param) {
- $name = trim($session_param['name']);
- $year_start = intval($session_param['year_start']);
- $month_start = intval($session_param['month_start']);
- $day_start = intval($session_param['day_start']);
- $year_end = intval($session_param['year_end']);
- $month_end = intval($session_param['month_end']);
- $day_end = intval($session_param['day_end']);
- $nb_days_access_before = intval($session_param['nb_days_access_before']);
- $nb_days_access_after = intval($session_param['nb_days_access_after']);
- $original_session_id_value = $session_param['original_session_id_value'];
- $original_session_id_name = $session_param['original_session_id_name'];
- $orig_session_id_value[] = $original_session_id_value;
- $coach_username = $session_param['coach_username'];
- $nolimit = $session_param['nolimit'];
- $id_coach = $session_param['user_id'];
- $extra_list = $session_param['extra'];
- $id = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($id)) {
- $results[] = 0;
- continue;
- }
- if (empty($nolimit)) {
- $date_start="$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
- $date_end="$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
- } else {
- $date_start="";
- $date_end="";
- }
- if (empty($name)) {
- $results[] = 0; //SessionNameIsRequired
- continue;
- } elseif (empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start, $day_start, $year_start))) {
- $results[] = 0; //InvalidStartDate
- continue;
- } elseif (empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end, $day_end, $year_end))) {
- $results[] = 0; //InvalidEndDate
- continue;
- } elseif (empty($nolimit) && $date_start >= $date_end) {
- $results[] = 0; //StartDateShouldBeBeforeEndDate
- continue;
- } else {
- $startDate = new DateTime($date_start);
- $endDate = new DateTime($date_end);
- $diffStart = new DateInterval($nb_days_access_before);
- $diffEnd = new DateInterval($nb_days_access_after);
- $coachStartDate = $startDate->sub($diffStart);
- $coachEndDate = $endDate->add($diffEnd);
- $sessionInfo = api_get_session_info($id);
- SessionManager::edit_session(
- $id,
- $name,
- $date_start,
- $date_end,
- $date_start,
- $date_end,
- $coachStartDate->format('Y-m-d H:i:s'),
- $coachEndDate->format('Y-m-d H:i:s'),
- $id_coach,
- $sessionInfo['session_category_id'],
- $sessionInfo['visibility'],
- $sessionInfo['description'],
- $sessionInfo['show_description'],
- $sessionInfo['duration'],
- null,
- $_user['user_id']
- );
- if (is_array($extra_list) && count($extra_list) > 0) {
- foreach ($extra_list as $extra) {
- $extra_field_name = $extra['field_name'];
- $extra_field_value = $extra['field_value'];
- // Save the external system's id into session_field_value table.
- $res = SessionManager::update_session_extra_field_value(
- $id,
- $extra_field_name,
- $extra_field_value
- );
- }
- }
- $results[] = 1;
- continue;
- }
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /* Register WSSubscribeUserToCourse function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'originalUsersList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:deleteSessionParams[]')),
- 'tns:originalUsersList'
- );
- $server->wsdl->addComplexType(
- 'subscribeUserToCourseParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_value', 'type' => 'xsd:string')
- )
- );
- /* Register WSDeleteSession function */
- $server->wsdl->addComplexType(
- 'deleteSessionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'deleteSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:deleteSessionParams[]')),
- 'tns:deleteSessionParams'
- );
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'deleteSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'sessions' => array('name' => 'sessions', 'type' => 'tns:deleteSessionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_deleteSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_deleteSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_deleteSession[]')),
- 'tns:result_deleteSession'
- );
- $server->register('WSDeleteSession', // method name
- array('deleteSession' => 'tns:deleteSession'), // input parameters
- array('return' => 'tns:results_deleteSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSDeleteSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service deletes a session ' // documentation
- );
- // define the method WSDeleteSession
- function WSDeleteSession($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
- $session_params = $params['sessions'];
- $results = array();
- $orig_session_id_value = array();
- foreach ($session_params as $session_param) {
- $original_session_id_value = $session_param['original_session_id_value'];
- $original_session_id_name = $session_param['original_session_id_name'];
- $orig_session_id_value[] = $original_session_id_name;
- $idChecked = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($idChecked)) {
- $results[] = 0;
- continue;
- }
- $session_ids[] = $idChecked;
- $sql = "DELETE FROM $tbl_session WHERE id = '$idChecked'";
- Database::query($sql);
- $sql = "DELETE FROM $tbl_session_rel_course WHERE session_id = '$idChecked'";
- Database::query($sql);
- $sql = "DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id = '$idChecked'";
- Database::query($sql);
- $sql = "DELETE FROM $tbl_session_rel_user WHERE session_id = '$idChecked'";
- Database::query($sql);
- $results[] = 1;
- continue;
- }
- $extraFieldValue = new ExtraFieldValue('session');
- //delete from table_session_field_value from a given session_id
- foreach ($session_ids as $session_id) {
- $extraFieldValue->deleteValuesByItem($session_id);
- }
- // Preparing output.
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /** WSSubscribeUserToCourse **/
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'user_course_status',
- 'complexType',
- 'struct',
- 'all',
- '',
- array (
- 'course_id' => array('name' => 'course_id', 'type' => 'tns:course_id'),
- 'user_id' => array('name' => 'user_id', 'type' => 'tns:user_id'),
- 'status' => array('name' => 'status', 'type' => 'xsd:int')
- )
- );
- $server->wsdl->addComplexType(
- 'subscribeUserToCourse_arg',
- 'complexType',
- 'struct',
- 'all',
- '',
- array (
- 'userscourses' => array('name' => 'userscourses', 'type' => 'tns:user_course_status_array'), //removed []
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'user_course_status_array',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(
- array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_course_status[]')
- ),
- 'tns:user_course_status'
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'subscribeUserToCourse_return',
- 'complexType',
- 'struct',
- 'all',
- '',
- array (
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:int')
- )
- );
- // Register the method to expose
- $server->register('WSSubscribeUserToCourse', // method name
- array('subscribeUserToCourse' => 'tns:subscribeUserToCourse_arg'), // input parameters
- array('return' => 'tns:subscribeUserToCourse_return'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSSubscribeUserToCourse', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service subscribes a user to a course' // documentation
- );
- // define the method WSSubscribeUserToCourse
- function WSSubscribeUserToCourse($params) {
- global $debug;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- if ($debug) error_log('WSSubscribeUserToCourse params: '.print_r($params,1));
- $results = array();
- $userscourses = $params['userscourses'];
- foreach ($userscourses as $usercourse) {
- $original_course_id = $usercourse['course_id'];
- $original_user_id = $usercourse['user_id'];
- $status = STUDENT;
- if ($usercourse['status']) {
- $status = $usercourse['status'];
- }
- $result = array(
- 'original_user_id_value' => $original_user_id['original_user_id_value'],
- 'original_course_id_value' => $original_course_id['original_course_id_value'],
- 'result' => 1);
- // Get user id
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id['original_user_id_value'],
- $original_user_id['original_user_id_name']
- );
- if ($debug) error_log('WSSubscribeUserToCourse user_id: '.$user_id);
- if ($user_id == 0) {
- // If user was not found, there was a problem
- $result['result'] = 0;
- } else {
- // User was found
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id['original_course_id_value'],
- $original_course_id['original_course_id_name']
- );
- if (empty($courseInfo)) {
- // Course was not found
- $result['result'] = 0;
- } else {
- $course_code = $courseInfo['code'];
- if ($debug) error_log('WSSubscribeUserToCourse course_code: '.$course_code);
- if (!CourseManager::add_user_to_course($user_id, $course_code, $status)) {
- $result['result'] = 0;
- }
- }
- }
- $results[] = $result;
- }
- return $results;
- }
- /** WSSubscribeUserToCourse **/
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'subscribeUserToCourseSimple_arg',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'course' => array('name' => 'course', 'type' => 'xsd:string'), //Course string code
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'), //Chamilo user_id
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'Result',
- 'complexType',
- 'struct',
- 'all',
- '',
- array('message' => array('name' => 'message', 'type' => 'xsd:string'))
- );
- // Register the method to expose
- $server->register('WSSubscribeUserToCourseSimple', // method name
- array('subscribeUserToCourseSimple' => 'tns:subscribeUserToCourseSimple_arg'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSSubscribeUserToCourseSimple', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service subscribes a user to a course in a simple way' // documentation
- );
- // define the method WSSubscribeUserToCourse
- function WSSubscribeUserToCourseSimple($params) {
- global $debug;
- if ($debug) error_log('WSSubscribeUserToCourseSimple');
- if ($debug) error_log('Params '. print_r($params, 1));
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $result = array();
- $course_code = $params['course']; //Course code
- $user_id = $params['user_id']; //chamilo user id
- $status = STUDENT;
- // Get user id
- $user_data = api_get_user_info($user_id);
- if (empty($user_data)) {
- // If user was not found, there was a problem
- $result = "User $user_id does not exist";
- if ($debug) error_log($result);
- return $result;
- }
- if (!empty($course_code)) {
- $course_data = CourseManager::get_course_information($course_code);
- if (empty($course_data)) {
- // Course was not found
- $result = "Course $course_code does not exist in the platform ";
- if ($debug) error_log($result);
- } else {
- if ($debug) error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']);
- if (!CourseManager::add_user_to_course($user_id, $course_data['code'], $status)) {
- $result = 'User was not registered possible reasons: User already registered to the course, Course visibility doesnt allow user subscriptions ';
- if ($debug) error_log($result);
- } else {
- if ($debug) error_log('User registered to the course: '.$course_data['code']);
- $result = 1;
- }
- }
- }
- return $result;
- }
- /* GetUser */
- $server->wsdl->addComplexType(
- 'GetUserArg',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'User',
- 'complexType',
- 'struct',
- 'all',
- '',
- array (
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
- 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
- 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
- )
- );
- // Register the method to expose
- $server->register('WSGetUser', // method name
- array('GetUser' => 'tns:GetUserArg'), // input parameters
- array('return' => 'tns:User'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSGetUser', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service get user information by id' // documentation
- );
- // define the method WSGetUser
- function WSGetUser($params) {
- global $debug;
- if ($debug) error_log('WSGetUser');
- if ($debug) error_log('$params: '.print_r($params, 1));
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $result = array();
- // Get user id
- $user_id = UserManager::get_user_id_from_original_id(
- $params['original_user_id_value'],
- $params['original_user_id_name']
- );
- $user_data = api_get_user_info($user_id);
- if (empty($user_data)) {
- // If user was not found, there was a problem
- $result['user_id'] = '';
- $result['firstname'] = '';
- $result['lastname'] = '';
- } else {
- $result['user_id'] = $user_data['user_id'];
- $result['firstname'] = $user_data['firstname'];
- $result['lastname'] = $user_data['lastname'];
- }
- return $result;
- }
- $server->wsdl->addComplexType(
- 'GetUserArgUsername',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key','type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSGetUserFromUsername', // method name
- array('GetUserFromUsername' => 'tns:GetUserArgUsername'), // input params
- array('return' => 'tns:User'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSGetUserFromUsername', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service get user information by username' // documentation
- );
- // define the method WSGetUserFromUsername
- function WSGetUserFromUsername($params) {
- global $debug;
- if ($debug) error_log('WSGetUserFromUsername');
- if ($debug) error_log('$params: '.print_r($params, 1));
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $result = array();
- // Get user id
- $user_data = UserManager::get_user_info($params['username']);
- if (empty($user_data)) {
- // If user was not found, there was a problem
- $result['user_id'] = '';
- $result['firstname'] = '';
- $result['lastname'] = '';
- } else {
- $result['user_id'] = $user_data['user_id'];
- $result['firstname'] = $user_data['firstname'];
- $result['lastname'] = $user_data['lastname'];
- }
- return $result;
- }
- /* Register WSUnsubscribeUserFromCourse function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'unsuscribeUserFromCourseParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- )
- );
- $server->wsdl->addComplexType(
- 'unsuscribeUserFromCourseParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:unsuscribeUserFromCourseParams[]')),
- 'tns:unsuscribeUserFromCourseParams'
- );
- $server->wsdl->addComplexType(
- 'unsuscribeUserFromCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'userscourses' => array('name' => 'userscourses', 'type' => 'tns:unsuscribeUserFromCourseParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_unsuscribeUserFromCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'xsd:string'),
- 'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_unsuscribeUserFromCourse',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_unsuscribeUserFromCourse[]')),
- 'tns:result_unsuscribeUserFromCourse'
- );
- // Register the method to expose
- $server->register('WSUnsubscribeUserFromCourse', // method name
- array('unsuscribeUserFromCourse' => 'tns:unsuscribeUserFromCourse'), // input parameters
- array('return' => 'tns:results_unsuscribeUserFromCourse'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSUnsubscribeUserFromCourse', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service unsubscribes a user from a course' // documentation
- );
- // define the method WSUnsubscribeUserFromCourse
- function WSUnsubscribeUserFromCourse($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $user_table = Database::get_main_table(TABLE_MAIN_USER);
- $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
- $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $userscourses_params = $params['userscourses'];
- $results = array();
- $orig_user_id_value = array();
- $orig_course_id_value = array();
- foreach ($userscourses_params as $usercourse_param) {
- $original_user_id_values = $usercourse_param['original_user_id_values'];
- $original_user_id_name = $usercourse_param['original_user_id_name'];
- $original_course_id_value = $usercourse_param['original_course_id_value'];
- $original_course_id_name = $usercourse_param['original_course_id_name'];
- $orig_course_id_value[] = $original_course_id_value;
- // Get user id from original user id
- $usersList = array();
- foreach ($original_user_id_values as $key => $row_original_user_id) {
- $user_id = UserManager::get_user_id_from_original_id($original_user_id_values[$key], $original_user_id_name[$key]);
- if ($user_id == 0) {
- continue; // user_id doesn't exist.
- } else {
- $sql = "SELECT user_id FROM $user_table WHERE user_id ='".$user_id."' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- continue; // user_id is not active.
- }
- }
- $usersList[] = $user_id;
- }
- $orig_user_id_value[] = implode(',',$usersList);
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $original_course_id_value,
- $original_course_id_name
- );
- if (empty($courseInfo) ||
- (isset($courseInfo) && $courseInfo['visibility'] == 0)
- ) {
- $results[] = 0;
- continue; // Original_course_id_value doesn't exist.
- }
- $courseId = $courseInfo['real_id'];
- if (count($usersList) == 0) {
- $results[] = 0;
- continue;
- }
- foreach ($usersList as $user_id) {
- $sql = "DELETE FROM $table_course_user
- WHERE user_id = '$user_id' AND c_id = '".$courseId."'";
- $result = Database::query($sql);
- $return = Database::affected_rows($result);
- }
- $results[] = 1;
- continue;
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_values' => $orig_user_id_value[$i],
- 'original_course_id_value' => $orig_course_id_value[$i],
- 'result' => $results[$i]
- );
- }
- return $output;
- }
- /* Register WSSuscribeUsersToSession function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'subscribeUsersToSessionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'subscribeUsersToSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:subscribeUsersToSessionParams[]')),
- 'tns:subscribeUsersToSessionParams'
- );
- $server->wsdl->addComplexType(
- 'subscribeUsersToSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'userssessions' => array('name' => 'userssessions', 'type' => 'tns:subscribeUsersToSessionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array.
- $server->wsdl->addComplexType(
- 'result_subscribeUsersToSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_subscribeUsersToSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_subscribeUsersToSession[]')),
- 'tns:result_subscribeUsersToSession'
- );
- // Register the method to expose
- $server->register('WSSuscribeUsersToSession', // method name
- array('subscribeUsersToSession' => 'tns:subscribeUsersToSession'), // input parameters
- array('return' => 'tns:results_subscribeUsersToSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSSuscribeUsersToSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service subscribes a user to a session' // documentation
- );
- // define the method WSSuscribeUsersToSession
- function WSSuscribeUsersToSession($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $user_table = Database::get_main_table(TABLE_MAIN_USER);
- $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $userssessions_params = $params['userssessions'];
- $results = array();
- $orig_user_id_value = array();
- $orig_session_id_value = array();
- foreach ($userssessions_params as $usersession_params) {
- $original_session_id_value = $usersession_params['original_session_id_value'];
- $original_session_id_name = $usersession_params['original_session_id_name'];
- $original_user_id_name = $usersession_params['original_user_id_name'];
- $original_user_id_values = $usersession_params['original_user_id_values'];
- $orig_session_id_value[] = $original_session_id_value;
- $sessionId = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($sessionId)) {
- $results[] = 0;
- continue;
- }
- $usersList = array();
- foreach ($original_user_id_values as $key => $row_original_user_list) {
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_values[$key],
- $original_user_id_name[$key]
- );
- if ($user_id == 0) {
- continue; // user_id doesn't exist.
- } else {
- $sql = "SELECT user_id FROM $user_table
- WHERE user_id ='".$user_id."' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- continue; // user_id is not active.
- }
- }
- $usersList[] = $user_id;
- }
- if (empty($usersList)) {
- $results[] = 0;
- continue;
- }
- $orig_user_id_value[] = implode(',', $usersList);
- if ($sessionId != strval(intval($sessionId))) {
- $results[] = 0;
- continue;
- }
- $sql = "SELECT user_id FROM $tbl_session_rel_user
- WHERE session_id='$sessionId' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."";
- $result = Database::query($sql);
- $existingUsers = array();
- while($row = Database::fetch_array($result)){
- $existingUsers[] = $row['user_id'];
- }
- $sql = "SELECT c_id FROM $tbl_session_rel_course WHERE session_id='$sessionId'";
- $result=Database::query($sql);
- $CourseList = array();
- while ($row = Database::fetch_array($result)) {
- $CourseList[] = $row['c_id'];
- }
- foreach ($CourseList as $enreg_course) {
- // For each course in the session...
- $nbr_users = 0;
- $enreg_course = Database::escape_string($enreg_course);
- // insert new users into session_rel_course_rel_user and ignore if they already exist
- foreach ($usersList as $enreg_user) {
- if (!in_array($enreg_user, $existingUsers)) {
- $enreg_user = Database::escape_string($enreg_user);
- $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(session_id, c_id, user_id)
- VALUES('$sessionId', '$enreg_course', '$enreg_user')";
- $result = Database::query($sql);
- Event::addEvent(
- LOG_SESSION_ADD_USER_COURSE,
- LOG_USER_ID,
- $enreg_user,
- api_get_utc_datetime(),
- api_get_user_id(),
- $enreg_course,
- $sessionId
- );
- if (Database::affected_rows($result)) {
- $nbr_users++;
- }
- }
- }
- // count users in this session-course relation
- $sql = "SELECT COUNT(user_id) as nbUsers
- FROM $tbl_session_rel_course_rel_user
- WHERE session_id = '$sessionId' AND c_id='$enreg_course'";
- $rs = Database::query($sql);
- list($nbr_users) = Database::fetch_array($rs);
- // update the session-course relation to add the users total
- $update_sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users
- WHERE session_id='$sessionId' AND c_id='$enreg_course'";
- Database::query($update_sql);
- }
- // insert missing users into session
- $nbr_users = 0;
- foreach ($usersList as $enreg_user) {
- $enreg_user = Database::escape_string($enreg_user);
- $nbr_users++;
- $sql = "INSERT IGNORE INTO $tbl_session_rel_user(session_id, user_id, registered_at)
- VALUES ('$sessionId','$enreg_user', '" . api_get_utc_datetime() . "')";
- Database::query($sql);
- }
- // update number of users in the session
- $nbr_users = count($usersList);
- $sql = "UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$sessionId' ";
- $result = Database::query($sql);
- Database::affected_rows($result);
- $results[] = 1;
- continue;
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_values' => $orig_user_id_value[$i],
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i]
- );
- }
- return $output;
- }
- // WSSubscribeUserToSessionSimple
- $server->wsdl->addComplexType(
- 'subscribeUserToSessionSimple_arg',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'session' => array('name' => 'session', 'type' => 'xsd:string'), // Session ID
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'), // Chamilo user_id
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- $server->register('WSSubscribeUserToSessionSimple', // method name
- array('subscribeUserToSessionSimple' => 'tns:subscribeUserToSessionSimple_arg'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSSubscribeUserToSessionSimple', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service subscribes a user to a session in a simple way' // documentation
- );
- function WSSubscribeUserToSessionSimple($params) {
- global $debug;
- if ($debug) {
- error_log('WSSubscribeUserToSessionSimple with params=[' . serialize($params). ']');
- }
- // Check security key
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- // Get input parameters
- $session_id = intval($params['session']); // Session ID
- $user_id = intval($params['user_id']); // Chamilo user id
- // Get user id
- $user_data = api_get_user_info($user_id);
- // Prepare answer
- $result = 0;
- if (empty($user_data)) {
- $result = "User {$user_id} does not exist";
- if ($debug) {
- error_log($result);
- }
- return $result;
- }
- if (!empty($session_id) && is_numeric($session_id)) {
- $session_data = api_get_session_info($session_id);
- if (empty($session_data)) {
- $result = "Session {$session_id} does not exist.";
- if ($debug) {
- error_log($result);
- }
- } else {
- SessionManager::suscribe_users_to_session(
- $session_id,
- array($user_id),
- SESSION_VISIBLE_READ_ONLY,
- false
- );
- if ($debug) error_log('User registered to the course: '.$session_id);
- $result = 1;
- }
- }
- return $result;
- }
- /* Register WSUnsuscribeUsersFromSession function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'unsubscribeUsersFromSessionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'),
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'unsubscribeUsersFromSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:unsubscribeUsersFromSessionParams[]')),
- 'tns:unsubscribeUsersFromSessionParams'
- );
- $server->wsdl->addComplexType(
- 'unsubscribeUsersFromSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'userssessions' => array('name' => 'userssessions', 'type' => 'tns:subscribeUsersToSessionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_unsubscribeUsersFromSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_values' => array('name' => 'original_user_id_values', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_unsubscribeUsersFromSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_unsubscribeUsersFromSession[]')),
- 'tns:result_unsubscribeUsersFromSession'
- );
- // Register the method to expose
- $server->register('WSUnsuscribeUsersFromSession', // method name
- array('unsubscribeUsersFromSession' => 'tns:unsubscribeUsersFromSession'), // input parameters
- array('return' => 'tns:results_unsubscribeUsersFromSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSUnsuscribeUsersFromSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service unsubscribes a user to a session' // documentation
- );
- // define the method WSUnsuscribeUsersFromSession
- function WSUnsuscribeUsersFromSession($params) {
- if(!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $user_table = Database::get_main_table(TABLE_MAIN_USER);
- $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $userssessions_params = $params['userssessions'];
- $results = array();
- $orig_user_id_value = array();
- $orig_session_id_value = array();
- foreach ($userssessions_params as $usersession_params) {
- $original_session_id_value = $usersession_params['original_session_id_value'];
- $original_session_id_name = $usersession_params['original_session_id_name'];
- $original_user_id_name = $usersession_params['original_user_id_name'];
- $original_user_id_values = $usersession_params['original_user_id_values'];
- $orig_session_id_value[] = $original_session_id_value;
- $id_session = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($id_session)) {
- $results[] = 0;
- continue;
- }
- $usersList = array();
- foreach ($original_user_id_values as $key => $row_original_user_list) {
- $user_id = UserManager::get_user_id_from_original_id(
- $original_user_id_values[$key],
- $original_user_id_name[$key]
- );
- if ($user_id == 0) {
- continue; // user_id doesn't exist.
- } else {
- $sql = "SELECT user_id FROM $user_table
- WHERE user_id ='".$user_id."' AND active= '0'";
- $resu = Database::query($sql);
- $r_check_user = Database::fetch_row($resu);
- if (!empty($r_check_user[0])) {
- continue; // user_id is not active.
- }
- }
- $usersList[] = $user_id;
- }
- if (empty($usersList)) {
- $results[] = 0;
- continue;
- }
- $orig_user_id_value[] = implode(',', $usersList);
- if ($id_session!= strval(intval($id_session))) {
- $results[] = 0;
- continue;
- }
- $sql = "SELECT user_id FROM $tbl_session_rel_user
- WHERE session_id ='$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."";
- $result = Database::query($sql);
- $existingUsers = array();
- while($row = Database::fetch_array($result)){
- $existingUsers[] = $row['user_id'];
- }
- $sql = "SELECT c_id FROM $tbl_session_rel_course WHERE session_id='$id_session'";
- $result = Database::query($sql);
- $CourseList = array();
- while ($row = Database::fetch_array($result)) {
- $CourseList[] = $row['c_id'];
- }
- foreach ($CourseList as $enreg_course) {
- // for each course in the session
- $nbr_users = 0;
- $enreg_course = Database::escape_string($enreg_course);
- foreach ($existingUsers as $existing_user) {
- if (!in_array($existing_user, $usersList)) {
- $sql = "DELETE FROM $tbl_session_rel_course_rel_user
- WHERE session_id ='$id_session' AND c_id='$enreg_course' AND user_id='$existing_user'";
- $result = Database::query($sql);
- if (Database::affected_rows($result)) {
- $nbr_users--;
- }
- }
- }
- // Count users in this session-course relation.
- $sql = "SELECT COUNT(user_id) as nbUsers
- FROM $tbl_session_rel_course_rel_user
- WHERE session_id = '$id_session' AND c_id='$enreg_course'";
- $rs = Database::query($sql);
- list($nbr_users) = Database::fetch_array($rs);
- // update the session-course relation to add the users total
- $update_sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users
- WHERE session_id ='$id_session' AND c_id ='$enreg_course'";
- Database::query($update_sql);
- }
- // Insert missing users into session.
- foreach ($usersList as $enreg_user) {
- $enreg_user = Database::escape_string($enreg_user);
- $delete_sql = "DELETE FROM $tbl_session_rel_user
- WHERE
- session_id = '$id_session' AND
- user_id = '$enreg_user' AND
- relation_type<>".SESSION_RELATION_TYPE_RRHH."";
- $result = Database::query($delete_sql);
- Event::addEvent(
- LOG_SESSION_DELETE_USER,
- LOG_USER_ID,
- $enreg_user,
- api_get_utc_datetime(),
- api_get_user_id(),
- 0,
- $id_session
- );
- $return = Database::affected_rows($result);
- }
- $nbr_users = 0;
- $sql = "SELECT nbr_users FROM $tbl_session WHERE id = '$id_session'";
- $res_nbr_users = Database::query($sql);
- $row_nbr_users = Database::fetch_row($res_nbr_users);
- if (Database::num_rows($res_nbr_users) > 0) {
- $nbr_users = ($row_nbr_users[0] - $return);
- }
- // Update number of users in the session.
- $update_sql = "UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' ";
- $result = Database::query($update_sql);
- $return = Database::affected_rows($result);
- $results[] = 1;
- continue;
- } // end principal foreach
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_user_id_values' => $orig_user_id_value[$i],
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i]
- );
- }
- return $output;
- }
- /* Register WSSuscribeCoursesToSession function */
- // Register the data structures used by the service
- /*$server->wsdl->addComplexType(
- 'originalCoursesList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'string[]')),
- 'xsd:string'
- );*/
- $server->wsdl->addComplexType(
- 'course_code_type',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'course_code' => array('name' => 'course_code', 'type' => 'xsd:string'),
- )
- );
- $server->wsdl->addComplexType(
- 'originalCoursesList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_code_type[]')),
- 'tns:course_code_type'
- );
- $server->wsdl->addComplexType(
- 'subscribeCoursesToSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:subscribeCoursesToSessionParams[]')),
- 'tns:subscribeCoursesToSessionParams'
- );
- $server->wsdl->addComplexType(
- 'subscribeCoursesToSessionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_values' => array('name' => 'original_course_id_values', 'type' => 'tns:originalCoursesList'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'subscribeCoursesToSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:subscribeCoursesToSessionParams[]')),
- 'tns:subscribeCoursesToSessionParams'
- );
- $server->wsdl->addComplexType(
- 'subscribeCoursesToSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'coursessessions' => array('name' => 'coursessessions', 'type' => 'tns:subscribeCoursesToSessionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_subscribeCoursesToSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_values' => array('name' => 'original_course_id_values', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_subscribeCoursesToSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_subscribeCoursesToSession[]')),
- 'tns:result_subscribeCoursesToSession'
- );
- // Register the method to expose
- $server->register('WSSuscribeCoursesToSession', // method name
- array('subscribeCoursesToSession' => 'tns:subscribeCoursesToSession'), // input parameters
- array('return' => 'tns:results_subscribeCoursesToSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSSuscribeCoursesToSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service subscribes a course to a session' // documentation
- );
- // Define the method WSSuscribeCoursesToSession
- function WSSuscribeCoursesToSession($params) {
- global $debug;
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- if ($debug) error_log('WSSuscribeCoursesToSession: '.print_r($params, 1));
- // initialisation
- $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
- $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $coursessessions_params = $params['coursessessions'];
- $results = array();
- $orig_course_id_value = array();
- $orig_session_id_value = array();
- foreach ($coursessessions_params as $coursesession_param) {
- $original_session_id_value = $coursesession_param['original_session_id_value'];
- $original_session_id_name = $coursesession_param['original_session_id_name'];
- $original_course_id_name = $coursesession_param['original_course_id_name'];
- $original_course_id_values = $coursesession_param['original_course_id_values'];
- $orig_session_id_value[] = $original_session_id_value;
- $id_session = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($id_session)) {
- $results[] = 0;
- continue;
- }
- // Get course list from row_original_course_id_values
- $course_list = [];
- $courseCodeList = [];
- foreach ($original_course_id_values as $row_original_course_list) {
- $course_code = Database::escape_string($row_original_course_list['course_code']);
- $courseInfo = api_get_course_info($course_code);
- $courseId = $courseInfo['real_id'];
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $course_code,
- $original_course_id_name
- );
- if (empty($courseInfo) ||
- (isset($courseInfo) && $courseInfo['visibility'] == 0)
- ) {
- $results[] = 0;
- continue; // Original_course_id_value doesn't exist.
- }
- $courseCodeList[] = $courseInfo['code'];
- $course_list[] = $courseInfo['real_id'];
- }
- if (empty($course_list)) {
- $results[] = 0;
- continue;
- }
- $orig_course_id_value[] = implode(',', $courseCodeList);
- // Get general coach ID
- $sql = "SELECT id_coach FROM $tbl_session WHERE id='$id_session'";
- $id_coach = Database::query($sql);
- $id_coach = Database::fetch_array($id_coach);
- $id_coach = $id_coach[0];
- // get list of courses subscribed to this session
- $sql = "SELECT c_id FROM $tbl_session_rel_course WHERE session_id ='$id_session'";
- $rs = Database::query($sql);
- $existingCourses = Database::store_result($rs);
- $nbr_courses = count($existingCourses);
- // get list of users subscribed to this session
- $sql= "SELECT user_id FROM $tbl_session_rel_user
- WHERE session_id = '$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."";
- $result = Database::query($sql);
- $user_list = Database::store_result($result);
- $course_directory = array();
- // Pass through the courses list we want to add to the session.
- foreach ($course_list as $enreg_course) {
- $enreg_course = Database::escape_string($enreg_course);
- $exists = false;
- // Check if the course we want to add is already subscribed.
- foreach ($existingCourses as $existingCourse) {
- if ($enreg_course == $existingCourse['c_id']) {
- $exists = true;
- }
- }
- if (!$exists) {
- // if the course isn't subscribed yet
- $sql = "INSERT INTO $tbl_session_rel_course (session_id, c_id)
- VALUES ('$id_session','$enreg_course')";
- Database::query($sql);
- Event::addEvent(
- LOG_SESSION_ADD_COURSE,
- LOG_COURSE_ID,
- $enreg_course,
- api_get_utc_datetime(),
- api_get_user_id(),
- $enreg_course,
- $id_session
- );
- // We add the current course in the existing courses array,
- // to avoid adding another time the current course
- $existingCourses[] = array('c_id' => $enreg_course);
- $nbr_courses++;
- // subscribe all the users from the session to this course inside the session
- $nbr_users = 0;
- foreach ($user_list as $enreg_user) {
- $enreg_user_id = Database::escape_string($enreg_user['user_id']);
- $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user (session_id, c_id, user_id)
- VALUES ('$id_session','$enreg_course','$enreg_user_id')";
- Event::addEvent(
- LOG_SESSION_ADD_USER_COURSE,
- LOG_USER_ID,
- $enreg_user_id,
- api_get_utc_datetime(),
- api_get_user_id(),
- $enreg_course,
- $id_session
- );
- $result = Database::query($sql);
- if (Database::affected_rows($result)) {
- $nbr_users++;
- }
- }
- $sql = "UPDATE $tbl_session_rel_course SET
- nbr_users = $nbr_users
- WHERE session_id='$id_session' AND c_id='$enreg_course'";
- Database::query($sql);
- $sql_directory = "SELECT directory FROM $tbl_course WHERE id = '$enreg_course'";
- $res_directory = Database::query($sql_directory);
- $row_directory = Database::fetch_row($res_directory);
- $course_directory[] = $row_directory[0];
- }
- }
- Database::query("UPDATE $tbl_session SET nbr_courses=$nbr_courses WHERE id='$id_session'");
- $course_directory[] = $id_session;
- $cad_course_directory = implode(',', $course_directory);
- $results[] = $cad_course_directory;
- continue;
- }
- $count_results = count($results);
- $output = array();
- for ($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_values' => $orig_course_id_value[$i],
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i]
- );
- }
- return $output;
- }
- /* Register WSUnsuscribeCoursesFromSession function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'unsubscribeCoursesFromSessionParams',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_values' => array('name' => 'original_course_id_values', 'type' => 'tns:originalCoursesList'),
- 'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'original_session_id_name' => array('name' => 'original_session_id_name', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'unsubscribeCoursesFromSessionParamsList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:unsubscribeCoursesFromSessionParams[]')),
- 'tns:unsubscribeCoursesFromSessionParams'
- );
- $server->wsdl->addComplexType(
- 'unsubscribeCoursesFromSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'coursessessions' => array('name' => 'coursessessions', 'type' => 'tns:unsubscribeCoursesFromSessionParamsList'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Prepare output params, in this case will return an array
- $server->wsdl->addComplexType(
- 'result_unsubscribeCoursesFromSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_course_id_values' => array('name' => 'original_course_id_values', 'type' => 'xsd:string'),
- 'original_session_id_value' => array('name' => 'original_session_id_value', 'type' => 'xsd:string'),
- 'result' => array('name' => 'result', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'results_unsubscribeCoursesFromSession',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_unsubscribeCoursesFromSession[]')),
- 'tns:result_unsubscribeCoursesFromSession'
- );
- // Register the method to expose
- $server->register('WSUnsuscribeCoursesFromSession', // method name
- array('unsubscribeCoursesFromSession' => 'tns:unsubscribeCoursesFromSession'), // input parameters
- array('return' => 'tns:results_unsubscribeCoursesFromSession'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSUnsuscribeCoursesFromSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service subscribes a course to a session' // documentation
- );
- // define the method WSUnsuscribeCoursesFromSession
- function WSUnsuscribeCoursesFromSession($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- // Initialisation
- $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $coursessessions_params = $params['coursessessions'];
- $results = array();
- $orig_course_id_value = array();
- $orig_session_id_value = array();
- foreach ($coursessessions_params as $coursesession_param) {
- $original_session_id_value = $coursesession_param['original_session_id_value'];
- $original_session_id_name = $coursesession_param['original_session_id_name'];
- $original_course_id_name = $coursesession_param['original_course_id_name'];
- $original_course_id_values = $coursesession_param['original_course_id_values'];
- $orig_session_id_value[] = $original_session_id_value;
- $id_session = SessionManager::getSessionIdFromOriginalId(
- $original_session_id_value,
- $original_session_id_name
- );
- if (empty($id_session)) {
- $results[] = 0;
- continue;
- }
- // Get courses list from row_original_course_id_values
- $course_list = array();
- $courseIdList = [];
- foreach ($original_course_id_values as $row_original_course_list) {
- $course_code = Database::escape_string($row_original_course_list['course_code']);
- // Check whether exits $x_course_code into user_field_values table.
- $courseInfo = CourseManager::getCourseInfoFromOriginalId(
- $row_original_course_list['course_code'],
- $original_course_id_name
- );
- if (empty($courseInfo) || isset($courseInfo) &&
- $courseInfo['visibility'] == 0
- ) {
- continue; // Course_code doesn't exist'
- }
- $course_list[] = $courseInfo['code'];
- $courseIdList[] = $courseInfo['real_id'];
- }
- if (empty($course_list)) {
- $results[] = 0;
- continue;
- }
- $orig_course_id_value[] = implode(',', $course_list);
- foreach ($courseIdList as $courseId) {
- $courseId = intval($courseId);
- Database::query("DELETE FROM $tbl_session_rel_course
- WHERE c_id ='$courseId' AND session_id='$id_session'");
- $result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE c_id='$courseId' AND session_id = '$id_session'");
- Event::addEvent(
- LOG_SESSION_DELETE_COURSE,
- LOG_COURSE_ID,
- $courseId,
- api_get_utc_datetime(),
- api_get_user_id(),
- $courseId,
- $id_session
- );
- $return = Database::affected_rows($result);
- }
- $nbr_courses = 0;
- $sql = "SELECT nbr_courses FROM $tbl_session WHERE id = '$id_session'";
- $res_nbr_courses = Database::query($sql);
- $row_nbr_courses = Database::fetch_row($res_nbr_courses);
- if (Database::num_rows($res_nbr_courses) > 0) {
- $nbr_users = ($row_nbr_courses[0] - $return);
- }
- // Update number of users in the session.
- $update_sql = "UPDATE $tbl_session SET nbr_courses= $nbr_courses WHERE id='$id_session' ";
- Database::query($update_sql);
- $results[] = 1;
- continue;
- }
- $count_results = count($results);
- $output = array();
- for($i = 0; $i < $count_results; $i++) {
- $output[] = array(
- 'original_course_id_values' => $orig_course_id_value[$i],
- 'original_session_id_value' => $orig_session_id_value[$i],
- 'result' => $results[$i],
- );
- }
- return $output;
- }
- /** WSListCourses **/
- $server->wsdl->addComplexType(
- 'course',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'id' => array('name' => 'id', 'type' => 'xsd:int'),
- 'code' => array('name' => 'code', 'type' => 'xsd:string'),
- 'external_course_id' => array('name' => 'external_course_id', 'type' => 'xsd:string'),
- 'title' => array('name' => 'title', 'type' => 'xsd:string'),
- 'language' => array('name' => 'language', 'type' => 'xsd:string'),
- 'category_name' => array('name' => 'category_name', 'type' => 'xsd:string'),
- 'visibility' => array('name' => 'visibility', 'type' => 'xsd:int'),
- 'number_students' => array('name' => 'number_students', 'type' => 'xsd:int')
- )
- );
- $server->wsdl->addComplexType(
- 'courses',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course[]')),
- 'tns:course'
- );
- // Register the method to expose
- $server->register('WSListCourses', // method name
- array('secret_key' => 'xsd:string', 'original_course_id_name' => 'xsd:string'), // input parameters
- array('return' => 'tns:courses'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSListCourses', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service list courses available on the system' // documentation
- );
- // define the method WSListCourses
- function WSListCourses($params)
- {
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $course_field_name = isset($params['original_course_id_name']) ? $params['original_course_id_name'] : '';
- $courses_result = array();
- $category_names = array();
- $courses = CourseManager::get_courses_list();
- foreach ($courses as $course) {
- $course_tmp = array();
- $course_tmp['id'] = $course['id'];
- $course_tmp['code'] = $course['code'];
- $course_tmp['title'] = $course['title'];
- $course_tmp['language'] = $course['course_language'];
- $course_tmp['visibility'] = $course['visibility'];
- // Determining category name
- if (!empty($course['category_code']) &&
- $category_names[$course['category_code']]
- ) {
- $course_tmp['category_name'] = $category_names[$course['category_code']];
- } else {
- $category = CourseManager::get_course_category($course['category_code']);
- $category_names[$course['category_code']] = $category['name'];
- $course_tmp['category_name'] = $category['name'];
- }
- // Determining number of students registered in course
- $course_tmp['number_students'] = CourseManager::get_users_count_in_course(
- $course['code']
- );
- // Determining external course id
- $externalCourseId = '';
- if ($course_field_name) {
- $externalCourseId = CourseManager::get_course_extra_field_value(
- $course_field_name,
- $course['code']
- );
- }
- $course_tmp['external_course_id'] = $externalCourseId;
- $courses_result[] = $course_tmp;
- }
- return $courses_result;
- }
- /* Get user api key */
- $server->wsdl->addComplexType(
- 'userApiKey',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
- 'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
- 'chamilo_username' => array('name' => 'chamilo_username', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSUpdateUserApiKey', // method name
- array('userApiKey' => 'tns:userApiKey'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSListCourses', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service return user api key' // documentation
- );
- function WSUpdateUserApiKey($params) {
- if(!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $user_id = UserManager::get_user_id_from_original_id($params['original_user_id_value'], $params['original_user_id_name']);
- if (!$user_id) {
- if (!empty($params['chamilo_username'])) {
- $info = api_get_user_info_from_username($params['chamilo_username']);
- $user_id = $info['user_id'];
- // Save new fieldlabel into user_field table.
- $field_id = UserManager::create_extra_field($params['original_user_id_name'], 1, $params['original_user_id_name'], '');
- // Save the external system's id into user_field_value table.
- $res = UserManager::update_extra_field_value($user_id, $params['original_user_id_name'], $params['original_user_id_value']);
- }
- else {
- return 0;
- }
- }
- $list = UserManager::get_api_keys($user_id);
- $key_id = UserManager::get_api_key_id($user_id, 'dokeos');
- if (isset($list[$key_id])) {
- $apikey = $list[$key_id];
- } else {
- $lastid = UserManager::update_api_key($user_id, 'dokeos');
- if ($lastid) {
- $apikeys = UserManager::get_api_keys($user_id);
- $apikey = $apikeys[$lastid];
- }
- }
- return $apikey;
- }
- /** WSListSessions **/
- $server->wsdl->addComplexType(
- 'session_arg',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'date_start' => array('name' => 'date_start', 'type' => 'xsd:string'),
- 'date_end' => array('name' => 'date_end', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'session',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'id' => array ('name' => 'id' , 'type' => 'xsd:int'),
- 'title' => array ('name' => 'title', 'type' => 'xsd:string'),
- 'url' => array ('name' => 'url', 'type' => 'xsd:string'),
- 'date_start' => array ('name' => 'date_start', 'type' => 'xsd:string'),
- 'date_end' => array ('name' => 'date_end', 'type' => 'xsd:string'),
- )
- );
- $server->wsdl->addComplexType(
- 'sessions',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(
- array('ref'=>'SOAP-ENC:arrayType',
- 'wsdl:arrayType'=>'tns:session[]')
- ),
- 'tns:session'
- );
- // Register the method to expose
- $server->register('WSListSessions', // method name
- array('input' => 'tns:session_arg'), // input parameters
- array('return' => 'tns:sessions'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSListSessions', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service returns a list of sessions' // documentation
- );
- /**
- * Get a list of sessions (id, title, url, date_start, date_end) and
- * return to caller. Date start can be set to ask only for the sessions
- * starting at or after this date. Date end can be set to ask only for the
- * sessions ending before or at this date.
- * Function registered as service. Returns strings in UTF-8.
- * @param array List of parameters (security key, date_start and date_end)
- * @return array Sessions list (id=>[title=>'title',url='http://...',date_start=>'...',date_end=>''])
- */
- function WSListSessions($params) {
- if(!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $sql_params = array();
- // Dates should be provided in YYYY-MM-DD format, UTC
- if (!empty($params['date_start'])) {
- $sql_params['s.access_start_date'] = array('operator' => '>=', 'value' => $params['date_start']);
- }
- if (!empty($params['date_end'])) {
- $sql_params['s.access_end_date'] = array('operator' => '<=', 'value' => $params['date_end']);
- }
- $sessions_list = SessionManager::get_sessions_list($sql_params);
- $return_list = array();
- foreach ($sessions_list as $session) {
- $return_list[] = array(
- 'id' => $session['id'],
- 'title' => $session['name'],
- 'url' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session['id'], // something like http://my.chamilo.net/main/session/index.php?session_id=5
- 'date_start' => $session['access_start_date'],
- 'date_end' => $session['access_end_date'],
- );
- }
- return $return_list;
- }
- /* Register WSUserSubscribedInCourse function */
- // Register the data structures used by the service
- //prepare input params
- // Input params for editing users
- $server->wsdl->addComplexType(
- 'UserSubscribedInCourse',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'course' => array('name' => 'course', 'type' => 'xsd:string'), //Course string code
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'), //Chamilo user_id
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSUserSubscribedInCourse', // method name
- array('UserSubscribedInCourse' => 'tns:UserSubscribedInCourse'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSUserSubscribedInCourse', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service checks if user assigned to course' // documentation
- );
- /**
- * Web service to tell if a given user is subscribed to the course
- * @param array $params Array of parameters (course and user_id)
- * @return bool|null|soap_fault A simple boolean (true if user is subscribed, false otherwise)
- */
- function WSUserSubscribedInCourse ($params)
- {
- global $debug;
- if ($debug) error_log('WSUserSubscribedInCourse');
- if ($debug) error_log('Params '. print_r($params, 1));
- if (!WSHelperVerifyKey($params)) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $courseCode = $params['course']; //Course code
- $userId = $params['user_id']; //chamilo user id
- return (CourseManager::is_user_subscribed_in_course($userId,$courseCode));
- }
- /* Search session Web Service start */
- // Input params for WSSearchSession
- $server->wsdl->addComplexType(
- 'SearchSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'term' => array('name' => 'term', 'type' => 'xsd:string'),
- 'extrafields' => array('name' => 'extrafields', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- //Output params for WSSearchSession
- $server->wsdl->addComplexType(
- 'searchedSessionExtra',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'variable' => array('name'=>'variable','type'=>'xsd:string'),
- 'value' => array('name'=>'value','type'=>'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'searchedSessionExtras',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(
- array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:searchedSessionExtra[]')
- ),
- 'tns:searchedSessionExtra'
- );
- $server->wsdl->addComplexType(
- 'searchedSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'id' => array('name' => 'id', 'type' => 'xsd:int'),
- 'id_coach' => array('name' => 'id_coach', 'type' => 'xsd:int'),
- 'name' => array('name' => 'name', 'type' => 'xsd:string'),
- 'nbr_courses' => array('name' => 'nbr_courses', 'type' => 'xsd:int'),
- 'nbr_users' => array('name' => 'nbr_users', 'type' => 'xsd:int'),
- 'nbr_classes' => array('name' => 'nbr_classes', 'type' => 'xsd:int'),
- 'date_start' => array('name' => 'date_start', 'type' => 'xsd:string'),
- 'date_end' => array('name' => 'date_end', 'type' => 'xsd:string'),
- 'nb_days_access_before_beginning' => array('name' => 'nb_days_access_before_beginning', 'type' => 'xsd:int'),
- 'nb_days_access_after_end' => array('nb_days_access_after_end' => 'duration', 'type' => 'xsd:int'),
- 'session_admin_id' => array('session_admin_id' => 'duration', 'type' => 'xsd:int'),
- 'visibility' => array('visibility' => 'duration', 'type' => 'xsd:int'),
- 'session_category_id' => array('session_category_id' => 'duration', 'type' => 'xsd:int'),
- 'promotion_id' => array('promotion_id' => 'duration', 'type' => 'xsd:int'),
- 'description' => array('name' => 'description', 'type' => 'xsd:string'),
- 'show_description' => array('name' => 'description', 'type' => 'xsd:int'),
- 'duration' => array('name' => 'duration', 'type' => 'xsd:string'),
- 'extra' => array('name' => 'extra', 'type' => 'tns:searchedSessionExtras'),
- )
- );
- $server->wsdl->addComplexType(
- 'searchedSessionList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(
- array('ref' => 'SOAP-ENC:arrayType',
- 'wsdl:arrayType' => 'tns:searchedSession[]')
- ),
- 'tns:searchedSession'
- );
- //Reister WSSearchSession
- $server->register(
- 'WSSearchSession',
- array('SearchSession' => 'tns:SearchSession'), // input parameters
- array('return' => 'tns:searchedSessionList'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSSearchSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service to get a session list filtered by name, description or short description extra field' // documentation
- );
- /**
- * Web service to get a session list filtered by name, description or short description extra field
- * @param array $params Contains the following parameters
- * string $params['term'] Search term
- * string $params['extra_fields'] Extrafields to include in request result
- * string $params['secret_key'] Secret key to check
- * @return array The list
- */
- function WSSearchSession($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $fieldsToInclude = array();
- if (!empty($params['extrafields'])) {
- $fieldsToInclude = explode(',', $params['extrafields']);
- foreach ($fieldsToInclude as &$field) {
- if (empty($field)) {
- continue;
- }
- $field = trim($field);
- }
- }
- return SessionManager::searchSession($params['term'], $fieldsToInclude);
- }
- /* Search session Web Service end */
- /* Fetch session Web Service start */
- // Input params for WSFetchSession
- $server->wsdl->addComplexType(
- 'FetchSession',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'id' => array('name' => 'id', 'type' => 'xsd:int'),
- 'extrafields' => array('name' => 'extrafields', 'type' => 'xsd:string'),
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
- )
- );
- //Reister WSFetchSession
- $server->register(
- 'WSFetchSession',
- array('SearchSession' => 'tns:FetchSession'), // input parameters
- array('return' => 'tns:searchedSessionList'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSFetchSession', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service get a session by its id. Optionally can get its extra fields values' // documentation
- );
- /**
- * Web service to get a session by its id. Optionally can get its extra fields values
- * @param array $params Contains the following parameters:
- * int $params['id'] The session id
- * string $params['extrafields'] Extrafields to include in request result
- * string $params['secret_key'] Secret key to check
- * @return array The session data
- */
- function WSFetchSession($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $fieldsToInclude = explode(',', $params['extrafields']);
- foreach ($fieldsToInclude as &$field) {
- if (empty($field)) {
- continue;
- }
- $field = trim($field);
- }
- $sessionData = SessionManager::fetch($params['id']);
- if ($sessionData === false) {
- return return_error(WS_ERROR_INVALID_INPUT);
- }
- if (!empty($extraFields)) {
- $sessionData['extra'] = SessionManager::getFilteredExtraFields($params['id'], $fieldsToInclude);
- }
- return array($sessionData);
- }
- /* Fetch session Web Service end */
- /* Register WSCertificatesList function */
- // Register the data structures used by the service
- $server->wsdl->addComplexType(
- 'certificateDetails',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'id' => array('name' => 'id', 'type' => 'xsd:int'),
- 'username' => array('name' => 'username', 'type' => 'xsd:string'),
- 'course_code' => array('name' => 'course_code', 'type' => 'xsd:string'),
- 'session_id' => array('name' => 'session_id', 'type' => 'xsd:int'),
- 'cat_id' => array('name' => 'cat_id', 'type' => 'xsd:int'),
- 'created_at' => array('name' => 'created_at', 'type' => 'xsd:string'),
- 'path_certificate' => array('name' => 'path_certificate', 'type' => 'xsd:string')
- )
- );
- $server->wsdl->addComplexType(
- 'certificatesList',
- 'complexType',
- 'array',
- '',
- 'SOAP-ENC:Array',
- array(),
- array(
- array('ref'=>'SOAP:ENC:arrayType',
- 'wsdl:arrayType'=>'tns:certificateDetails[]')
- ),
- 'tns:certificateDetails'
- );
- // Register the method to expose
- $server->register(
- 'WSCertificatesList', // method name
- array(
- 'startingDate' => 'xsd:string', // input parameters
- 'endingDate' => 'xsd:string'
- ),
- array('return' => 'tns:certificatesList'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCertificatesList', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service returns a list of certificates' // documentation
- );
- function WSCertificatesList($startingDate = '', $endingDate = '')
- {
- global $_configuration;
- $certificatesCron = api_get_setting('add_gradebook_certificates_cron_task_enabled');
- if ($certificatesCron === 'true') {
- require_once api_get_path(SYS_CODE_PATH).'cron/add_gradebook_certificates.php';
- }
- $result = array();
- $certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $userTable = Database::get_main_table(TABLE_MAIN_USER);
- $categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
- $query = "SELECT
- certificate.id,
- user.username,
- category.course_code,
- category.session_id,
- certificate.user_id,
- certificate.cat_id,
- certificate.created_at,
- certificate.path_certificate
- FROM $certificateTable AS certificate
- JOIN $userTable AS user
- ON certificate.user_id = user.user_id
- JOIN $categoryTable AS category
- ON certificate.cat_id = category.id";
- if (!empty($startingDate) && !empty($endingDate)) {
- $query .= " WHERE certificate.created_at BETWEEN '$startingDate' AND '$endingDate'";
- } else if (!empty($startingDate)) {
- $query .= " WHERE certificate.created_at >= '$startingDate'";
- } else if (!empty($endingDate)) {
- $query .= " WHERE certificate.created_at <= '$endingDate'";
- }
- $queryResult = Database::query($query);
- while ($row = Database::fetch_array($queryResult)) {
- $userPath = USermanager::getUserPathById($row['user_id'], 'web');
- $row['path_certificate'] = $userPath.'/certificate'.$row['path_certificate'];
- $result[] = $row;
- }
- return $result;
- }
- /* Create group Web Service start */
- // Register the data structures used by the service
- // Input params for WSCreateGroup
- $server->wsdl->addComplexType(
- 'createGroup',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'name' => array('name' => 'name', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSCreateGroup', // method name
- array('createGroup' => 'tns:createGroup'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSCreateGroup', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds a group' // documentation
- );
- // Define the method WSCreateGroup
- function WSCreateGroup($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- $params = [
- 'name' => $params['name']
- ];
- return $userGroup->save($params);
- //return GroupPortalManager::add($params['name'], null, null, 1);
- }
- /* Create group Web Service end */
- /* Update group Web Service start */
- // Register the data structures used by the service
- // Input params for WSUpdateGroup
- $server->wsdl->addComplexType(
- 'updateGroup',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'id' => array('name' => 'id', 'type' => 'xsd:string'),
- 'name' => array('name' => 'name', 'type' => 'xsd:string'),
- 'description' => array('name' => 'description', 'type' => 'xsd:string'),
- 'url' => array('name' => 'url', 'type' => 'xsd:string'),
- 'visibility' => array('name' => 'visibility', 'type' => 'xsd:string'),
- 'picture_uri' => array('name' => 'picture_uri', 'type' => 'xsd:string'),
- 'allow_member_group_to_leave' => array('name' => 'allow_member_group_to_leave', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSUpdateGroup', // method name
- array('updateGroup' => 'tns:updateGroup'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSUpdateGroup', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service updates a group' // documentation
- );
- // Define the method WSUpdateGroup
- function WSUpdateGroup($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $params['allow_member_group_to_leave'] = null;
- $userGroup = new UserGroup();
- return $userGroup->update($params);
- /*return GroupPortalManager::update(
- $params['id'],
- $params['name'],
- $params['description'],
- $params['url'],
- $params['visibility'],
- $params['picture_uri'],
- $params['allow_member_group_to_leave']
- );*/
- }
- /* Update group Web Service end */
- /* Delete group Web Service start */
- // Register the data structures used by the service
- // Input params for WSDeleteGroup
- $server->wsdl->addComplexType(
- 'deleteGroup',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'id' => array('name' => 'id', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSDeleteGroup', // method name
- array('deleteGroup' => 'tns:deleteGroup'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSDeleteGroup', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service deletes a group' // documentation
- );
- // Define the method WSDeleteGroup
- function WSDeleteGroup($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- return $userGroup->delete($params['id']);
- //return GroupPortalManager::delete($params['id']);
- }
- /* Delete group Web Service end */
- /* Bind group to parent Web Service start */
- // Register the data structures used by the service
- // Input params for GroupBindToParent
- $server->wsdl->addComplexType(
- 'groupBindToParent',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'id' => array('name' => 'id', 'type' => 'xsd:string'),
- 'parent_id' => array('name' => 'parent_id', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('GroupBindToParent', // method name
- array('groupBindToParent' => 'tns:groupBindToParent'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#GroupBindToParent', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service binds a group to a parent' // documentation
- );
- // Define the method GroupBindToParent
- function GroupBindToParent($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- return $userGroup->set_parent_group($params['id'], $params['parent_id']);
- //return GroupPortalManager::set_parent_group($params['id'], $params['parent_id']);
- }
- /* Bind group Web Service end */
- /* Unbind group from parent Web Service start */
- // Register the data structures used by the service
- // Input params for GroupUnbindFromParent
- $server->wsdl->addComplexType(
- 'groupUnbindFromParent',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'id' => array('name' => 'id', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('GroupUnbindFromParent', // method name
- array('groupUnbindFromParent' => 'tns:groupUnbindFromParent'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#GroupUnbindFromParent', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service unbinds a group from its parent' // documentation
- );
- // Define the method GroupUnbindFromParent
- function GroupUnbindFromParent($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- return $userGroup->set_parent_group($params['id'], 0);
- }
- /* Unbind group Web Service end */
- /* Add user to group Web Service start */
- // Register the data structures used by the service
- // Input params for WSAddUserToGroup
- $server->wsdl->addComplexType(
- 'addUserToGroup',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
- 'group_id' => array('name' => 'group_id', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSAddUserToGroup', // method name
- array('addUserToGroup' => 'tns:addUserToGroup'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSAddUserToGroup', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service adds a user to a group' // documentation
- );
- // Define the method WSAddUserToGroup
- function WSAddUserToGroup($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- return $userGroup->add_user_to_group($params['user_id'], $params['group_id']);
- }
- /* Add user to group Web Service end */
- /* Update user role in group Web Service start */
- // Register the data structures used by the service
- // Input params for WSUpdateUserRoleInGroup
- $server->wsdl->addComplexType(
- 'updateUserRoleInGroup',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
- 'group_id' => array('name' => 'group_id', 'type' => 'xsd:string'),
- 'relation_type' => array('name' => 'relation_type', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSUpdateUserRoleInGroup', // method name
- array('updateUserRoleInGroup' => 'tns:updateUserRoleInGroup'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSUpdateUserRoleInGroup', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service updates a user role in group' // documentation
- );
- // Define the method WSUpdateUserRoleInGroup
- function WSUpdateUserRoleInGroup($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- return $userGroup->update_user_role(
- $params['user_id'],
- $params['group_id'],
- $params['relation_type']
- );
- }
- /* Update user role Web Service end */
- /* Delete user from group Web Service start */
- // Register the data structures used by the service
- // Input params for WSDeleteUserFromGroup
- $server->wsdl->addComplexType(
- 'deleteUserFromGroup',
- 'complexType',
- 'struct',
- 'all',
- '',
- array(
- 'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
- 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
- 'group_id' => array('name' => 'group_id', 'type' => 'xsd:string')
- )
- );
- // Register the method to expose
- $server->register('WSDeleteUserFromGroup', // method name
- array('deleteUserFromGroup' => 'tns:deleteUserFromGroup'), // input parameters
- array('return' => 'xsd:string'), // output parameters
- 'urn:WSRegistration', // namespace
- 'urn:WSRegistration#WSDeleteUserFromGroup', // soapaction
- 'rpc', // style
- 'encoded', // use
- 'This service deletes a user from a group' // documentation
- );
- // Define the method WSDeleteUserFromGroup
- function WSDeleteUserFromGroup($params)
- {
- if (!WSHelperVerifyKey($params['secret_key'])) {
- return return_error(WS_ERROR_SECRET_KEY);
- }
- $userGroup = new UserGroup();
- return $userGroup->delete_user_rel_group(
- $params['user_id'],
- $params['group_id']
- );
- }
- /* Delete user from group Web Service end */
- // Add more webservices through hooks from plugins
- if (!empty($hook)) {
- $hook->setEventData(array('server' => $server));
- $res = $hook->notifyWSRegistration(HOOK_EVENT_TYPE_POST);
- if (!empty($res['server'])) {
- $server = $res['server'];
- }
- }
- // Use the request to (try to) invoke the service
- $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
- $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
- // If you send your data in utf8 then this value must be false.
- $decodeUTF8 = api_get_setting('registration.soap.php.decode_utf8');
- if ($decodeUTF8 === 'true') {
- $server->decode_utf8 = true;
- } else {
- $server->decode_utf8 = false;
- }
- $server->service($HTTP_RAW_POST_DATA);
|